|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-07-02 20:04 UTC] Husman85 at gmail dot com
[2016-11-19 17:37 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2016-11-19 17:37 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 23:00:01 2025 UTC |
Description: ------------ Due to some reasons we are not allowed to create property with empty name: $object = new stdClass(); $object->{""} = 42; // Fatal error: Cannot access empty property Ok. But type-cast `(object)` doesn't know about this restriction: http://3v4l.org/IU3GW . This inconsistency cause some problems. All PHP/5 versions affected including PHP/5.5 and PHP/5.6.0beta3: Some features emits a notice, others aren't. Some features interacts with empty property, others aren't. (there are some different behaviours in very old versions) Test script: --------------- <?php $object = (object) array( "foo" => 42, "" => 37, "bar" => 19, ); echo "+ object created:\n"; var_dump($object); echo "\nenum properties:\n"; foreach ($object as $p => $v) { var_dump($p); } echo "\nget_object_vars()\n"; var_dump(get_object_vars($object)); Expected result: ---------------- Fatal error: Cannot access empty property (or an Exception should be better) Actual result: -------------- + object created: object(stdClass)#1 (3) { ["foo"]=> int(42) Notice: Illegal member variable name in ... on line 9 [""]=> int(37) ["bar"]=> int(19) } enum properties: string(3) "foo" Notice: Illegal member variable name in ... on line 12 string(3) "bar" get_object_vars() Notice: Illegal member variable name in ... on line 17 array(2) { ["foo"]=> int(42) ["bar"]=> int(19) }