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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC