PHP 5.2 JSON Libraries

I want to implement a stable C5 install for a university. I am wondering about the PHP 5.2 + recommendation.

The system requirements page says that C5 uses some JSON libs bundled in PHP 5.2 +

Does anyone know if these libs can be added to PHP 5.1.6 without moving to 5.2?

RHEL repos are frozen at PHP 5.1.x, upgrading only for security. In the environment I must install into, following the RHN versions is necessary.

So, to recap, can I make PHP 5.1.6 fully compatible with C5, if so, what do I need?

View Replies:
andrew replied on at Permalink Reply
The only JSON functionality we use is the function "json_encode." There is a drop-in function listed on this page:

which people have told me works. It's listed in one of the comments. You could try adding it before


that's in index.php and see if everything works. Basically it looks to see if json_encode exists and if it doesn't, implements a workaround. Since this is the only reason we need PHP 5.2, we will likely implement something like this in a compatibility layer for our next release, so that problems like yours don't happen (since otherwise C5 should work fine in PHP 5.1.)
vercasson replied on at Permalink Reply
function json_encode($a)
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a)) {
$a = addslashes($a);
$a = str_replace("\n", '\n', $a);
$a = str_replace("\r", '\r', $a);
$a = preg_replace('{(</)(script)}i', "$1'+'$2", $a);
return "'$a'";
$isList = true;
for ($i=0, reset($a); $i<count($a); $i++, next($a))
if (key($a) !== $i) { $isList = false; break; }
$result = array();
if ($isList) {
foreach ($a as $v) $result[] = json_encode($v);
return '[ ' . join(', ', $result) . ' ]';
} else {
foreach ($a as $k=>$v)
$result[] = json_encode($k) . ': ' . json_encode($v);
return '{ ' . join(', ', $result) . ' }';