#41505 [NEW]: json_encode() improperly encodes PHP arrays with an empty string array key

From: Date: Sat, 26 May 2007 07:33:10 +0000
Subject: #41505 [NEW]: json_encode() improperly encodes PHP arrays with an empty string array key
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-113042@lists.php.net to get a copy of this message
From: jmorrow at jessejmorrow dot com Operating system: OS X PHP version: 5.2.2 PHP Bug Type: Unknown/Other Function Bug description: json_encode() improperly encodes PHP arrays with an empty string array key Description: ------------ The json_encode() function completely ignores, and thus does not encode, PHP array entries with an array key that is an empty string: array (""=>"value"); Empty string array keys and object properties are totally valid PHP and JSON respectively - they should encode/decode as such. This, along with the corresponding json_decode() bug of a similar nature (41504), are show stoppers for me as I need JSON encode/decode to be rock solid and consistent. Thanks for looking into this :-) Reproduce code: --------------- 1) var_dump(json_encode(array(""=>"value"))); 2) var_dump(json_encode(array(""=>"value1", "key2"=>"value2"))); Expected result: ---------------- 1) string(15) "{"":"value"}" 2) string(17) "{"":"value1", "key2":"value2"}" Actual result: -------------- 1) string(2) "{}" 2) string(17) "{"key2":"value2"}" In both cases the array entry with the empty string key is missing. This might be addressed by Bug #41034, but may very well be a different bug. -- Edit bug report at http://bugs.php.net/?id=41505&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41505&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41505&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41505&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41505&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41505&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41505&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41505&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41505&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41505&r=support Expected behavior: http://bugs.php.net/fix.php?id=41505&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41505&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41505&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41505&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41505&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41505&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41505&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41505&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41505&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41505&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41505&r=mysqlcfg

« previous php.bugs (#113042) next »