ID:               46600
 Comment by:       matt at mpcm dot com
 Reported By:      Matt at mpcm dot com
 Status:           Verified
 Bug Type:         JSON related
 Operating System: *
 PHP Version:      5CVS, 6CVS (2008-11-18)
 New Comment:

The language seems to create a key that cannot be reached, so even if
this `bug` is fixed, we am still facing a broader issue it seems.

<?
$key = "";
$o = (object) array($key=>4,"example"=>8);
var_dump($o);
print 'blank key test:' . (isset($o->$key)?'true':'false');
print $o->{$key};
var_dump($o->$key);
?>

output:
object(stdClass)#1 (2) {
  [""]=>
  int(4)
  ["example"]=>
  int(8)
}
blank key test:false<br />
<b>Fatal error</b>:  Cannot access empty property in
<b>PHPDocument1</b> on line <b>8</b><br />
All throws Notice: line 4 - Illegal member variable name


Previous Comments:
------------------------------------------------------------------------

[2008-11-18 15:43:05] matt at mpcm dot com

All the work arounds I am looking at are throwing Error Text: Illegal
member variable name when I convert/cast an object with a blank
property.

Is this json_decode `bug` a result of a larger object mechanism
limitation inside of php's object handling?

------------------------------------------------------------------------

[2008-11-18 03:13:51] Matt at mpcm dot com

Description:
------------
json_decode() treats empty property name as "_empty_" not "". This was
fixed in #41504 for arrays, but not for objects. (seems to happen in PHP
Version 5.2.4-2ubuntu5.3 and 5.3.0alpha2.

Reproduce code:
---------------
<?
$s = '{"":"test"}';
var_dump(json_decode($s));
?>


Expected result:
----------------
object(stdClass)#1 (1) { [""]=>  string(4) "test" }

Actual result:
--------------
object(stdClass)#2 (1) { ["_empty_"]=>  string(4) "test" }


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46600&edit=1

Reply via email to