Bug #46600 [NoF]: "_empty_" key in objects (see #41504)
| From: | ajf@php.net | Date: | Mon, 25 Jan 2016 14:56:33 +0000 |
| Subject: | Bug #46600 [NoF]: "_empty_" key in objects (see #41504) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198880@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=46600&edit=1
ID: 46600
Updated by: ajf@php.net
Reported by: Matt at mpcm dot com
Summary: "_empty_" key in objects (see #41504)
Status: No Feedback
Type: Bug
Package: JSON related
Operating System: *
PHP Version: 5CVS, 6CVS (2008-11-18)
Block user comment: N
Private report: N
New Comment:
This is arguably not a bug since you can't have objects with empty property names, so this is
necessary to allow decoding JSON objects with empty keys. However, that's a rather arbitrary
restriction. If we removed it, we could fix this.
Previous Comments:
------------------------------------------------------------------------
[2014-01-14 18:50:41] matt at mpcm dot com
Last post was a bad example, this is the actual output:
as object: {"_empty_":"c"}
as array: {"_empty_":"a","":"c"}
------------------------------------------------------------------------
[2014-01-14 18:48:23] matt at mpcm dot com
With an output of:
as object: {"_empty_":"c"}
as array: {"_empty_":"b","":"c"}
------------------------------------------------------------------------
[2014-01-14 18:47:27] matt at mpcm dot com
To illustrate the current collision state, as this came up on the JSMentors list recently.
<?php
$a =
'{"_empty_":"a","":"b","":"c"}';
echo "as object: " . json_encode(json_decode($a));
echo "\n";
echo "as array: " . json_encode(json_decode($a, true));
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
------------------------------------------------------------------------
[2009-08-12 22:49:59] scottmac@php.net
Works for me here with 5.2-dev and 5.3-dev
object(stdClass)#1 (2) {
["test2"]=>
int(5)
["_empty_"]=>
int(6)
}
------------------------------------------------------------------------
[2009-08-12 21:20:22] michaeldnelson dot mdn at gmail dot com
I am using freebsd 7.2 and php 5.2.10 the first test case
var_dump(json_decode('{"":"test"}'));
silently stops processing of the script
The test case
var_dump(json_decode('{"test2":5,"":6}'));
Fatal error: Cannot access empty property
I am not sure the second is expected behavior but considering json is often from feeds it would be
nice to fail more gracefully.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=46600
--
Edit this bug report at https://bugs.php.net/bug.php?id=46600&edit=1