From: jmorrow at jessejmorrow dot com
Operating system: OS X
PHP version: 5.2.2
PHP Bug Type: Unknown/Other Function
Bug description: json_decode() incorrectly decodes JSON objects with empty
string keys
Description:
------------
The json_decode() function improperly and incosistently decodes JSON
objects that have an empty string as one of their object keys/property
names. In some cases the server crashes, some cases work properly, and
other cases return "_empty_" as the array key.
The "_empty_" key and crashes are show stoppers for me.
Having an empty object key/property such as {"": "value"} is totally
valid, and even common, JSON.
As a side note, I'll open a separate bug for this, json_encode(array
(""=>"value")) does not work either.
Reproduce code:
---------------
1) var_dump(json_decode('{"":"value"}', true));
2) var_dump(json_decode('{"":"value", "key":"value"}', true));
3) var_dump(json_decode('{"key":"value", "":"value"}', true));
Expected result:
----------------
1) array(1) { [""]=> string(5) "value" }
2) array(2) { [""]=> string(5) "value" ["key"]=> string(5) "value" }
3) array(2) { ["key"]=> string(5) "value" [""]=> string(5) "value" }
Actual result:
--------------
1) Page fails to return - some kind of script crash
2) array(2) { ["_empty_"]=> string(5) "value" ["key"]=> string(5)
"value" } (the "_empty_" key coming up is the most common case when
there the key is an empty string)
3) array(2) { ["key"]=> string(5) "value" [""]=> string(5) "value" }
(works as expected)
--
Edit bug report at http://bugs.php.net/?id=41504&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41504&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41504&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41504&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41504&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41504&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41504&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41504&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41504&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41504&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41504&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41504&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41504&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41504&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41504&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41504&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41504&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41504&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41504&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41504&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41504&r=mysqlcfg