Bug #54513 [NEW]: json_decode skips value where json_encode includes it

From: Date: Tue, 12 Apr 2011 11:26:44 +0000
Subject: Bug #54513 [NEW]: json_decode skips value where json_encode includes it
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160118@lists.php.net to get a copy of this message
From:             
Operating system: Gentoo Linux x86
PHP version:      5.3.6
Package:          JSON related
Bug Type:         Bug
Bug description:json_decode skips value where json_encode includes it

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 bug report at http://bugs.php.net/bug.php?id=54513&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=54513&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=54513&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=54513&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=54513&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54513&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=54513&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=54513&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=54513&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=54513&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=54513&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=54513&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=54513&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=54513&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=54513&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54513&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54513&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=54513&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=54513&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=54513&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=54513&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=54513&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#160118) next »