From 430d05b058ac3df435600a678cda365dba3eb1b7 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Mon, 15 Nov 2010 00:38:54 +0100 Subject: Use native PHP JSON functions when available --- inc/JSON.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc/JSON.php') diff --git a/inc/JSON.php b/inc/JSON.php index 332827f4c..d1fbd404a 100644 --- a/inc/JSON.php +++ b/inc/JSON.php @@ -130,6 +130,7 @@ class JSON { /** * encodes an arbitrary variable into JSON format + * If available the native PHP JSON implementation is used. * * @param mixed $var any number, boolean, string, array, or object to be encoded. * see argument 1 to JSON() above for array-parsing behavior. @@ -140,6 +141,7 @@ class JSON { * @access public */ function encode($var) { + if (function_exists('json_encode')) return json_encode($var); switch (gettype($var)) { case 'boolean': return $var ? 'true' : 'false'; @@ -352,6 +354,7 @@ class JSON { /** * decodes a JSON string into appropriate variable + * If available the native PHP JSON implementation is used. * * @param string $str JSON-formatted string * @@ -363,6 +366,7 @@ class JSON { * @access public */ function decode($str) { + if (function_exists('json_decode')) return json_decode($str); $str = $this->reduce_string($str); switch (strtolower($str)) { -- cgit v1.2.3