|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-10-08 13:40 UTC] ceceldada at gmail dot com
Description:
------------
A stdClass shouldn't allow invalid proprieties names.
Numbers are not valid propriety name.
$object = new stdClass();
$object->0 = 1; //This is invalid
$object->{"\0"} = 1; //This is valid, why???
Test script:
---------------
<?php
$data = array( 'a', 'asdas' => 2312 );
print_r( (object) $data );
Expected result:
----------------
stdClass Object
(
[asdas] => 2312
)
Actual result:
--------------
stdClass Object
(
[0] => a
[asdas] => 2312
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 22:00:01 2025 UTC |
While it is not valid to define a property name with a leading digit in a class definition, the braced syntax in your example is a perfectly legal way of creating these kinds of properties. As an example, if these properties were illegal we wouldn't be able to work with JSON: $obj = json_decode('{"0": "hi"}'); var_dump($obj->{0}); // string(2) "hi" Thanks for taking the time to report this though.