Bug #70127 [Nab]: var_dump((object)array("123" => new stdclass, "123" => "muh"));

From: Date: Fri, 24 Jul 2015 13:40:22 +0000
Subject: Bug #70127 [Nab]: var_dump((object)array("123" => new stdclass, "123" => "muh"));
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194675@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70127&edit=1 ID: 70127 User updated by: office at moving-bytes dot at Reported by: office at moving-bytes dot at Summary: var_dump((object)array("123" => new stdclass, "123" => "muh")); Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 5.6.11 Assigned To: cmb Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2015-07-24 13:05:44] cmb@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. It is possible to have numeric property names by other means: $o = new StdClass(); $o->{123} = 'foo'; var_dump($o); This is a feature, and not a bug. ------------------------------------------------------------------------ [2015-07-24 12:40:21] 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" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70127&edit=1

« previous php.bugs (#194675) next »