Bug #68186 [Opn->Nab]: A stdClass shouldn't allow invalid proprieties names.
| From: | leigh@php.net | Date: | Wed, 08 Oct 2014 22:59:05 +0000 |
| Subject: | Bug #68186 [Opn->Nab]: A stdClass shouldn't allow invalid proprieties names. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187966@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68186&edit=1
ID: 68186
Updated by: leigh@php.net
Reported by: ceceldada at gmail dot com
Summary: A stdClass shouldn't allow invalid proprieties
names.
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2014-10-08 13:40:38] 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
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68186&edit=1