|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-08-29 17:04 UTC] kylekatarnls at gmail dot com
Description:
------------
Why can we not access property with empty name ?
I wish be able to do something like this :
$object->{""} = "Foo";
echo $object->{""};
Actualy, we can do :
$array = (array) $object;
$array[""] = "Foo";
echo $array[""];
$object = (object) $array;
So why could we not set and get the value of an property with empty name ?
Test script:
---------------
$object->{""} = "Foo";
echo $object->{""};
Expected result:
----------------
print Foo and throw any error or just a notice.
Actual result:
--------------
Fatal error : Cannot access empty property
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 14:00:01 2025 UTC |
However a object with empty property names can exist. So why if a do : $object = (object) [ '' => 'Foo' ]; There is no error. And if I do this : $object = new stdClass; $object->{''} = 'Foo'; There is a Fatal error for the same result ? Do not this codes should both throw the same error ? A warning sound good in my opinion.