ID: 41504 Updated by: [EMAIL PROTECTED] Reported By: jmorrow at jessejmorrow dot com -Status: Open +Status: Assigned Bug Type: Unknown/Other Function Operating System: OS X PHP Version: 5.2.2 -Assigned To: +Assigned To: iliaa New Comment:
I am unable to reproduce the crash with var_dump(json_decode('{"":"value"}', true)); it returns "_empty_" => "value" for me. Analysis through valgrind does not report any errors either. The issue of "" being returned as "_empty_" is a bug and will be fixed. Previous Comments: ------------------------------------------------------------------------ [2007-05-26 07:21:23] jmorrow at jessejmorrow dot com 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 this bug report at http://bugs.php.net/?id=41504&edit=1