Permalink
Browse files

MDL-16768 Added php version-dependent function definitions so that we…

… can use json_encode() and json_decode() no matter what PHP version the server is running.
  • Loading branch information...
1 parent 0b75065 commit 627e2cb6f5f14a0b4749479d5a0c2948087954ee nicolasconnault committed Oct 2, 2008
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/json/JSON.php
View
@@ -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]);
@@ -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.