|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-05-26 07:21 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 00:00:01 2025 UTC |
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.