From 36c55971b5a7cb85a442285f50d20dbd28db2f8a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Apr 2013 23:57:07 +0200 Subject: [PATCH] Fix: PHPUnit Regression --- htdocs/core/lib/json.lib.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 81a8b88117d..cf86ad1fc25 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -72,15 +72,16 @@ function dol_json_encode($elements) $output = '{'; $last = $num - 1; $i = 0; - if (is_array($elements) && count($elements)>0) { - foreach($elements as $key => $value) - { - $output .= '"'.$key.'":'; - if (is_array($value)) $output.= json_encode($value); - else $output .= _val($value); - if ($i !== $last) $output.= ','; - ++$i; - } + $tmpelements=array(); + if (is_array($elements)) $tmpelements=$elements; + if (is_object($elements)) $tmpelements=get_object_vars($elements); + foreach($tmpelements as $key => $value) + { + $output .= '"'.$key.'":'; + if (is_array($value)) $output.= json_encode($value); + else $output .= _val($value); + if ($i !== $last) $output.= ','; + ++$i; } $output.= '}'; }