Bug #52829 [PATCH]: json_decode looses data
| From: | aharvey@php.net | Date: | Tue, 14 Sep 2010 05:48:43 +0000 |
| Subject: | Bug #52829 [PATCH]: json_decode looses data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154318@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52829&edit=1
ID: 52829
Patch added by: aharvey@php.net
Reported by: pzbowen at gmail dot com
Summary: json_decode looses data
Status: Open
Type: Bug
Package: JSON related
Operating System: Linux
PHP Version: 5.2.14
Block user comment: N
New Comment:
The following patch has been added/updated:
Patch Name: json-decode-warnings
Revision: 1284443322
URL:
http://bugs.php.net/patch-display.php?bug=52829&patch=json-decode-warnings&revision=1284443322
Previous Comments:
------------------------------------------------------------------------
[2010-09-13 22:03:03] pzbowen at gmail dot com
Agreed, no easy way to handle it, so it should return an error when this
situation is encountered.
------------------------------------------------------------------------
[2010-09-13 21:49:13] kalle@php.net
I can't see any really easy way to achieve this since properties and
array keys are unique in PHP. Perhaps some overloading with objects but
that would be dirty/hackish
------------------------------------------------------------------------
[2010-09-13 20:31:49] pzbowen at gmail dot com
Description:
------------
According to RFC 4627, section 2.2, "The names within an object SHOULD
be unique." This is only a SHOULD not a MUST, so the following is
valid
{"foo":2,"foo":3}
Unfortunately in PHP this only returns the last object member.
Test script:
---------------
var_dump(json_decode('{"foo":2,"foo":3}'));
Expected result:
----------------
an object with a way of accessing both members or an error raised by
json_decode
Actual result:
--------------
object(stdClass)#1 (1) {
["foo"]=>
int(3)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52829&edit=1