#41505 [Asn->Csd]: json_encode() improperly encodes PHP arrays with an empty string array key
| From: | iliaa@php.net | Date: | Sun, 27 May 2007 16:33:00 +0000 |
| Subject: | #41505 [Asn->Csd]: json_encode() improperly encodes PHP arrays with an empty string array key | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113066@lists.php.net to get a copy of this message | ||
ID: 41505
Updated by: iliaa@php.net
Reported By: jmorrow at jessejmorrow dot com
-Status: Assigned
+Status: Closed
Bug Type: Unknown/Other Function
Operating System: OS X
PHP Version: 5.2.2
Assigned To: iliaa
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-05-26 07:33:10] jmorrow at jessejmorrow dot com
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 this bug report at http://bugs.php.net/?id=41505&edit=1