|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70127 var_dump((object)array("123" => new stdclass, "123" => "muh"));
Submitted: 2015-07-24 12:40 UTC Modified: 2016-08-12 12:22 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: office at moving-bytes dot at Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.6.11 OS: *
Private report: No CVE-ID: None
 [2015-07-24 12:40 UTC] office at moving-bytes dot at
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) {
  string(3) "foo"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-24 13:05 UTC]
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem -Operating System: +Operating System: * -Assigned To: +Assigned To: cmb
 [2015-07-24 13:05 UTC]
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 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';
This is a feature, and not a bug.
 [2015-07-24 13:40 UTC] office at moving-bytes dot at
-: office at moving-byte dot at +: office at moving-bytes dot at
 [2015-07-24 13:40 UTC] office at moving-bytes dot at
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?
 [2015-07-24 14:00 UTC]
IMHO, we really ought to fix that.

arrays store and access (rightfully, I guess) numeric keys as integers.
objects store and access all the keys as strings.

We maybe should do the same numeric access for dynamic properties on objects...
 [2015-07-24 14:01 UTC]
-Status: Not a bug +Status: Analyzed
 [2015-07-24 14:07 UTC]
I don't think so, it will be overhead while casting or accessing for rarely cases..

just with a good document should be fine.
 [2015-07-24 14:07 UTC]
I don't think so, it will be overhead while casting or accessing for rarely cases..

just with a good document should be fine.
 [2015-07-24 14:22 UTC]
The behavior when casting object to array is already well

> If an object is converted to an array, the result is an array
> whose elements are the object's properties. The keys are the
> member variable names, with a few notable exceptions: integer
> properties are unaccessible; [...]

[1] <>
 [2015-07-24 14:42 UTC]
-Assigned To: cmb +Assigned To:
 [2015-07-24 15:26 UTC]
@laruence: note that the overhead will only exist for dynamic property accesses (non-CONST VM operand and only on a dynamic access - meaning when there is no fast access to property table). Which should be a rare enough case … and that particular case is already relatively slow.

I think we could afford it?
 [2016-08-12 12:22 UTC]
-Status: Analyzed +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-08-12 12:22 UTC]
Duplicate of bug #66173.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 06:01:31 2024 UTC