|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesjsonserializedepth (last revision 2016-04-22 17:11 UTC by jani dot ollikainen at valve dot fi)jsonserializedepth-55 (last revision 2016-04-22 15:09 UTC by jani dot ollikainen at valve dot fi) Pull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2016-04-22 15:32 UTC] jani dot ollikainen at valve dot fi
[2017-01-09 05:42 UTC] krakjoe@php.net
-Status: Open
+Status: Feedback
[2017-01-09 05:42 UTC] krakjoe@php.net
[2017-01-22 04:22 UTC] php-bugs at lists dot php dot net
[2017-01-22 09:33 UTC] nikic@php.net
-Status: No Feedback
+Status: Open
[2017-01-22 09:33 UTC] nikic@php.net
[2017-04-30 15:20 UTC] bukka@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: bukka
[2017-04-30 15:20 UTC] bukka@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
Description: ------------ We have objects that do dynamic loading and there might be recursions. We could use recursion depth to decide when we want to do dynamic loading and when not. Now there doesn't seem to be any way to know how deep is the json_encode process going. If we try to use some level in jsonSerialize it just calls one of those, no recursion there. This could be easily archived by exposing the internal encoder_depth to jsonSerialize. Test script: --------------- <?php class O implements \JsonSerializable { public function jsonSerialize($depth = 0) { if ($depth >= 100) return array(); return array('i' => $this->i, 'o' => $this->o); } } $first = new O; $first->i = 0; $last = $first; for ($i = 1; $i < 500; $i++) { $new = New O; $new->i = $i; $new->o = null; $last->o = $new; $last = $new; } $ret = json_encode($first, 0, 256); var_dump($ret); $a=json_last_error(); var_dump($a); $b=json_last_error_msg(); var_dump($b); Expected result: ---------------- string(1292) "{"i":0,"o":{"i":1,"o":{"i":2,"o":{"i":3,"o":{"i":4,"o":{"i":5,"o":{"i":6,"o":{"i":7,"o":{"i":8,"o":{"i":9,"o":{"i":10,"o":{"i":11,"o":{"i":12,"o":{"i":13,"o":{"i":14,"o":{"i":15,"o":{"i":16,"o":{"i":17,"o":{"i":18,"o":{"i":19,"o":{"i":20,"o":{"i":21,"o":{"i":22,"o":{"i":23,"o":{"i":24,"o":{"i":25,"o":{"i":26,"o":{"i":27,"o":{"i":28,"o":{"i":29,"o":{"i":30,"o":{"i":31,"o":{"i":32,"o":{"i":33,"o":{"i":34,"o":{"i":35,"o":{"i":36,"o":{"i":37,"o":{"i":38,"o":{"i":39,"o":{"i":40,"o":{"i":41,"o":{"i":42,"o":{"i":43,"o":{"i":44,"o":{"i":45,"o":{"i":46,"o":{"i":47,"o":{"i":48,"o":{"i":49,"o":{"i":50,"o":{"i":51,"o":{"i":52,"o":{"i":53,"o":{"i":54,"o":{"i":55,"o":{"i":56,"o":{"i":57,"o":{"i":58,"o":{"i":59,"o":{"i":60,"o":{"i":61,"o":{"i":62,"o":{"i":63,"o":{"i":64,"o":{"i":65,"o":{"i":66,"o":{"i":67,"o":{"i":68,"o":{"i":69,"o":{"i":70,"o":{"i":71,"o":{"i":72,"o":{"i":73,"o":{"i":74,"o":{"i":75,"o":{"i":76,"o":{"i":77,"o":{"i":78,"o":{"i":79,"o":{"i":80,"o":{"i":81,"o":{"i":82,"o":{"i":83,"o":{"i":84,"o":{"i":85,"o":{"i":86,"o":{"i":87,"o":{"i":88,"o":{"i":89,"o":{"i":90,"o":{"i":91,"o":{"i":92,"o":{"i":93,"o":{"i":94,"o":{"i":95,"o":{"i":96,"o":{"i":97,"o":{"i":98,"o":{"i":99,"o":[]}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}" int(0) string(8) "No error" Actual result: -------------- bool(false) int(1) string(28) "Maximum stack depth exceeded"