|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-24 12:40 UTC] office at moving-bytes dot at
Description:
------------
Usually its not possible to create class and variablenames containing only numbers.
But if you create an array and typecast it to object, these rules does not exist anymore.
Test script:
---------------
var_dump((object)array("123" => new stdclass, "123" => "muh"));
Expected result:
----------------
PHP Parse error: syntax error, unexpected '123' (T_LNUMBER), expecting identifier (T_STRING)
Actual result:
--------------
object(stdClass)#1 (1) {
[123]=>
string(3) "foo"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Jan 01 12:00:01 2026 UTC |
imho this is a bug, since this is a complete inconsistent behavior: example from stackoverflow: $a = array('123' => '123'); $o1 = (object)$a; $o2 = new stdClass; $o2->{'123'} = '123'; // setting property is OK echo $o1->{'123'}; // error! echo $o2->{'123'}; // works... WTF? http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers/10333200#10333200