Skip to content

Commit

Permalink
Add a way to manage fallbacks for not implemented functions.
Browse files Browse the repository at this point in the history
Raise warning if try to use json_encode() when it's not available. PHP 5 < PHP 5.2.0 doesn't provide json functions natively.
  • Loading branch information
Fabrice Luraine authored and CBeerta committed May 30, 2011
1 parent 17e8bfe commit f26e049
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/limonade.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ function run($env = null)

# 3. Loading libs
require_once_dir(option('lib_dir'));
fallbacks_for_not_implemented_functions();

# 4. Starting session
if(!defined('SID') && option('session'))
Expand Down Expand Up @@ -1547,7 +1548,9 @@ function txt($content_or_func, $layout = '', $locals = array())
}

/**
* Returns json representation of data with proper http headers
* Returns json representation of data with proper http headers.
* On PHP 5 < PHP 5.2.0, you must provide your own implementation of the
* <code>json_encode()</code> function beore using <code>json()</code>.
*
* @param string $data
* @param int $json_option
Expand Down Expand Up @@ -2637,5 +2640,28 @@ function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
}
}

/**
* Called just after loading libs, it provides fallback for some
* functions if they don't exists.
*
*/
function fallbacks_for_not_implemented_functions()
{
if(!function_exists('json_encode'))
{
/**
* for PHP 5 < PHP 5.2.0
*
*/
function json_encode()
{
trigger_error(
__FUNCTION__ . '(): no JSON functions available. Please provide your own implementation of ' . __FUNCTION__ . '() in order to use it.', E_USER_WARNING
);
}
}
}



# ================================= END ================================== #

0 comments on commit f26e049

Please sign in to comment.