php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60379 Cannot access numeric property when object is created by casting from array
Submitted: 2011-11-25 01:03 UTC Modified: 2011-11-25 17:01 UTC
From: orangejasmine at hotmail dot com Assigned: cataphract (profile)
Status: Duplicate Package: *Programming Data Structures
PHP Version: 5.3.8 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: orangejasmine at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-11-25 01:03 UTC] orangejasmine at hotmail dot com
Description:
------------
An object loses access to property with numeric key when it was created by casting 
from array.
But string keys are ok.
Why????

Test script:
---------------
<?php
$o = new stdClass;
$o->{0} = 'Hello World';
print_r($o);
print_r(get_object_vars($o));
echo($o->{0} . "\n");
$o = (object)array(0 => 'Hello World');
print_r($o);
print_r(get_object_vars($o));
echo($o->{0} . "\n");
?>

Expected result:
----------------
stdClass Object
(
    [0] => Hello World
)
Array
(
    [0] => Hello World
)
Hello World
stdClass Object
(
    [0] => Hello World
)
Array
(
    [0] => Hello World
)
Hello World

Actual result:
--------------
stdClass Object
(
    [0] => Hello World
)
Array
(
    [0] => Hello World
)
Hello World
stdClass Object
(
    [0] => Hello World
)
Array
(
)
PHP Notice:  Undefined property: stdClass::$0 in ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-25 16:19 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2011-11-25 17:01 UTC] cataphract@php.net
Duplicate of #45959, which is wont fix. I'll bring the issue to the list.
 [2011-11-25 17:01 UTC] cataphract@php.net
-Status: Assigned +Status: Duplicate
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 02:03:36 2021 UTC