Skip to content

Commit

Permalink
MDL-16768 Added php version-dependent function definitions so that we…
Browse files Browse the repository at this point in the history
… can use json_encode() and json_decode() no matter what PHP version the server is running.
  • Loading branch information
nicolasconnault committed Oct 2, 2008
1 parent 0b75065 commit 627e2cb
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/json/JSON.php
Expand Up @@ -666,7 +666,7 @@ function decode($str)
// element in an associative array,
// for now
$parts = array();

if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// "name":value pair
$key = $this->decode($parts[1]);
Expand Down Expand Up @@ -802,5 +802,22 @@ function Services_JSON_Error($message = 'unknown error', $code = null,
}

}


// Future-friendly json_encode
if( !function_exists('json_encode') ) {
function json_encode($data) {
$json = new Services_JSON();
return( $json->encode($data) );
}
}

// Future-friendly json_decode
if( !function_exists('json_decode') ) {
function json_decode($data) {
$json = new Services_JSON();
return( $json->decode($data) );
}
}


?>

0 comments on commit 627e2cb

Please sign in to comment.