Doc #38945 [Com]: json_decode has limits on array depth.
| From: | " | Date: | Wed, 03 Mar 2010 17:28:08 +0000 |
| Subject: | Doc #38945 [Com]: json_decode has limits on array depth. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4007@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=38945&edit=1
ID: 38945
Comment by:
Reported by: RQuadling at GMail dot com
Summary: json_decode has limits on array depth.
Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: Windows XP SP2
PHP Version: Irrelevant
Assigned To: bjori
New Comment:
Sorry. The two symbols of the Republican Party: an elephant, and a big
fat white guy who is threatened by change. Help me! Please help find
sites for: Finasteride contraindicaciones. I found only this - <a
href="http://ceipbanus.xeill.net/Members/Finasteride/finasteride-shedding">finasteride
shedding</a>. Either similar or crappy, you can massage the alternative
cipro to spend tendonitis from the baldness, finasteride. Finasteride,
of loss, the evident prevention is the yogurt to enhance. With respect
:cool:, Geri from Zealand.
Previous Comments:
------------------------------------------------------------------------
[2007-05-25 19:29:32] bjori@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
The limit was 20, but was bumped to 128 in 5.2.3
------------------------------------------------------------------------
[2006-11-17 05:00:22] grebenshikov dot n at gmail dot com
json_decode also has limits on object depth.
class C2 {
public $text = 'Hello!';
}
class C1 {
public $next;
public $objs = array();
public function __construct($next) {
$this->next = $next;
for ($i=1; $i<=10; $i++) {
array_push($this->objs, new C2());
}
}
}
$first = new C1(false);
$obj = $first;
for ($i=1; $i<=17; $i++) {
$obj->next = new C1(false);
$obj = $obj->next;
}
print (json_encode($first));
print_r(json_decode(json_encode($first)));
------------------------------------------------------------------------
[2006-09-25 07:42:12] RQuadling at GMail dot com
Description:
------------
Massively nested arrays are decoded as null by json_decode.
Admittedly, an array this deep has its own concerns, but with no
warnings or notices, documentation of the limit would be advisable.
The following code has 2 arrays, the first is 18 levels, the second is
19. The first decodes correctly, the second decodes as null.
Whilst an array MAY not be this deep, it is possible that objects
containing objects with arrays COULD produce a depth of 19 levels. Sure,
not exactly LEAN, but that's why this is just a minor doc issue and not
a more important code issue.
The issue is with json_decode as json_encode quite happily encodes the
larger array - an inconsistency maybe as the json_decode dox does say
any json_encode'd output (though I am awaiting the changes due to
bug#38680).
It also makes no difference if you use the 'assoc' option (json_decode's
second paramater of True) to produce an associative array. The limit is
still reached at 19 levels.
Reproduce code:
---------------
<?php
$a_array =
array('One' => array('Two' => array('Three' =>
array('Four' =>
array('Five' => array('Six' => array('Seven' =>
array('Eight' =>
array('Nine' => array('Ten' => array('Eleven' =>
array('Twelve' =>
array('Thirteen' => array('Fourteen' => array('Fifteen' =>
array('Sixteen' => array('Seventeen' => array('Eighteen' =>
array(1,2,3)))))))))))))))))));
var_dump(json_encode($a_array));
var_dump(json_decode(json_encode($a_array)));
$a_array =
array('One' => array('Two' => array('Three' =>
array('Four' =>
array('Five' => array('Six' => array('Seven' =>
array('Eight' =>
array('Nine' => array('Ten' => array('Eleven' =>
array('Twelve' =>
array('Thirteen' => array('Fourteen' => array('Fifteen' =>
array('Sixteen' => array('Seventeen' => array('Eighteen' =>
array('Nineteen' => array(1,2,3))))))))))))))))))));
var_dump(json_encode($a_array));
var_dump(json_decode(json_encode($a_array)));
?>
Expected result:
----------------
string(195)
"{"One":{"Two":{"Three":{"Four":{"Five":{"Six":{"Seven":{"Eight":{"Nine":{"Ten":{"Eleven":{"Twelve":{"Thirteen":{"Fourteen":{"Fifteen":{"Sixteen":{"Seventeen":{"Eighteen":[1,2,3]}}}}}}}}}}}}}}}}}}"
object(stdClass)#1 (1) {
["One"]=>
object(stdClass)#2 (1) {
["Two"]=>
object(stdClass)#3 (1) {
["Three"]=>
object(stdClass)#4 (1) {
["Four"]=>
object(stdClass)#5 (1) {
["Five"]=>
object(stdClass)#6 (1) {
["Six"]=>
object(stdClass)#7 (1) {
["Seven"]=>
object(stdClass)#8 (1) {
["Eight"]=>
object(stdClass)#9 (1) {
["Nine"]=>
object(stdClass)#10 (1) {
["Ten"]=>
object(stdClass)#11 (1) {
["Eleven"]=>
object(stdClass)#12 (1) {
["Twelve"]=>
object(stdClass)#13 (1) {
["Thirteen"]=>
object(stdClass)#14 (1) {
["Fourteen"]=>
object(stdClass)#15 (1) {
["Fifteen"]=>
object(stdClass)#16 (1) {
["Sixteen"]=>
object(stdClass)#17 (1) {
["Seventeen"]=>
object(stdClass)#18 (1) {
["Eighteen"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
string(208)
"{"One":{"Two":{"Three":{"Four":{"Five":{"Six":{"Seven":{"Eight":{"Nine":{"Ten":{"Eleven":{"Twelve":{"Thirteen":{"Fourteen":{"Fifteen":{"Sixteen":{"Seventeen":{"Eighteen":{"Nineteen":[1,2,3]}}}}}}}}}}}}}}}}}}}"
object(stdClass)#1 (1) {
["One"]=>
object(stdClass)#2 (1) {
["Two"]=>
object(stdClass)#3 (1) {
["Three"]=>
object(stdClass)#4 (1) {
["Four"]=>
object(stdClass)#5 (1) {
["Five"]=>
object(stdClass)#6 (1) {
["Six"]=>
object(stdClass)#7 (1) {
["Seven"]=>
object(stdClass)#8 (1) {
["Eight"]=>
object(stdClass)#9 (1) {
["Nine"]=>
object(stdClass)#10 (1) {
["Ten"]=>
object(stdClass)#11 (1) {
["Eleven"]=>
object(stdClass)#12 (1) {
["Twelve"]=>
object(stdClass)#13 (1) {
["Thirteen"]=>
object(stdClass)#14 (1) {
["Fourteen"]=>
object(stdClass)#15 (1) {
["Fifteen"]=>
object(stdClass)#16 (1) {
["Sixteen"]=>
object(stdClass)#17 (1) {
["Seventeen"]=>
object(stdClass)#18 (1) {
["Eighteen"]=>
object(stdClass)#19 (1) {
["Nineteen"] =>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Actual result:
--------------
string(195)
"{"One":{"Two":{"Three":{"Four":{"Five":{"Six":{"Seven":{"Eight":{"Nine":{"Ten":{"Eleven":{"Twelve":{"Thirteen":{"Fourteen":{"Fifteen":{"Sixteen":{"Seventeen":{"Eighteen":[1,2,3]}}}}}}}}}}}}}}}}}}"
object(stdClass)#1 (1) {
["One"]=>
object(stdClass)#2 (1) {
["Two"]=>
object(stdClass)#3 (1) {
["Three"]=>
object(stdClass)#4 (1) {
["Four"]=>
object(stdClass)#5 (1) {
["Five"]=>
object(stdClass)#6 (1) {
["Six"]=>
object(stdClass)#7 (1) {
["Seven"]=>
object(stdClass)#8 (1) {
["Eight"]=>
object(stdClass)#9 (1) {
["Nine"]=>
object(stdClass)#10 (1) {
["Ten"]=>
object(stdClass)#11 (1) {
["Eleven"]=>
object(stdClass)#12 (1) {
["Twelve"]=>
object(stdClass)#13 (1) {
["Thirteen"]=>
object(stdClass)#14 (1) {
["Fourteen"]=>
object(stdClass)#15 (1) {
["Fifteen"]=>
object(stdClass)#16 (1) {
["Sixteen"]=>
object(stdClass)#17 (1) {
["Seventeen"]=>
object(stdClass)#18 (1) {
["Eighteen"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
string(208)
"{"One":{"Two":{"Three":{"Four":{"Five":{"Six":{"Seven":{"Eight":{"Nine":{"Ten":{"Eleven":{"Twelve":{"Thirteen":{"Fourteen":{"Fifteen":{"Sixteen":{"Seventeen":{"Eighteen":{"Nineteen":[1,2,3]}}}}}}}}}}}}}}}}}}}"
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=38945&edit=1