Edit report at http://bugs.php.net/bug.php?id=54513&edit=1
ID: 54513 User updated by: samu dot voutilainen at gmail dot com Reported by: samu dot voutilainen at gmail dot com Summary: json_decode skips value where json_encode includes it -Status: Feedback +Status: Closed Type: Bug Package: JSON related Operating System: Gentoo Linux x86 PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: Hmph, sorry, Iâm not able to reproduce it either... Previous Comments: ------------------------------------------------------------------------ [2011-04-12 17:23:31] scott...@php.net I need a reproduce script. I just used: <?php $test = new StdClass; $test->a = 1; $test->b = array(); $test->c = 'foo'; $json = json_encode($test); var_dump($test); var_dump(json_decode($json)); And I got the output: object(stdClass)#1 (3) { ["a"]=> int(1) ["b"]=> array(0) { } ["c"]=> string(3) "foo" } object(stdClass)#2 (3) { ["a"]=> int(1) ["b"]=> array(0) { } ["c"]=> string(3) "foo" } Nothing missing there. ------------------------------------------------------------------------ [2011-04-12 13:26:41] samu dot voutilainen at gmail dot com Description: ------------ If you have empty array inside object, json_encode() does encode the value into JSON format, but when the data is decoded with json_decode(), this empty JSON array is omitted from output. Consider following structure: ["timetable"]=> object(pizzaonline\model\Timetable)#30 (9) { ["id"]=> string(3) "774" ["timetable"]=> array(0) { } ["opening_hours"]=> .. Corresponding json_encode would be: "timetable":{ "id":"774", "timetable":[ ], "opening_hours":[ .. This is all right, but I have a loop that removes this empty array with unset(). So PHP structure from JSON is encoded is like: ["timetable"]=> object(pizzaonline\model\Timetable)#30 (8) { ["id"]=> string(3) "774" ["opening_hours"]=> But using json_encode() returns same result that is in snippet 2. Just ask if any questions, Iâll do example script later... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54513&edit=1