summaryrefslogtreecommitdiff
path: root/inc/JSON.php
diff options
context:
space:
mode:
authorAdrian Lang <mail@adrianlang.de>2011-04-22 22:35:43 +0200
committerAdrian Lang <mail@adrianlang.de>2011-04-22 22:35:43 +0200
commit8ccf9c9785ec2b626bad30a88a21f02886845418 (patch)
tree0ecd6103880e3350bd37ba11ae3872805ede1755 /inc/JSON.php
parente2092379b1c3200832cb569781ec647db5aeef0f (diff)
parent23d27376b2a2f6a1ccf0777c48435717494d85b1 (diff)
downloadrpg-8ccf9c9785ec2b626bad30a88a21f02886845418.tar.gz
rpg-8ccf9c9785ec2b626bad30a88a21f02886845418.tar.bz2
Merge branch 'master' into stable
Conflicts: data/deleted.files doku.php lib/exe/xmlrpc.php
Diffstat (limited to 'inc/JSON.php')
-rw-r--r--inc/JSON.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/inc/JSON.php b/inc/JSON.php
index 332827f4c..2dea44003 100644
--- a/inc/JSON.php
+++ b/inc/JSON.php
@@ -112,6 +112,16 @@ define('JSON_STRICT_TYPE', 11);
* @deprecated
*/
class JSON {
+
+ /**
+ * Disables the use of PHP5's native json_decode()
+ *
+ * You shouldn't change this usually because the native function is much
+ * faster. However, this non-native will also parse slightly broken JSON
+ * which might be handy when talking to a non-conform endpoint
+ */
+ public $skipnative = false;
+
/**
* constructs a new JSON instance
*
@@ -130,6 +140,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 +151,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 +364,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 +376,10 @@ class JSON {
* @access public
*/
function decode($str) {
+ if (!$this->skipnative && function_exists('json_decode')){
+ return json_decode($str,($this->use == JSON_LOOSE_TYPE));
+ }
+
$str = $this->reduce_string($str);
switch (strtolower($str)) {