Bug #60379 [Asn->Dup]: Cannot access numeric property when object is created by casting from array
Edit report at https://bugs.php.net/bug.php?id=60379&edit=1
ID: 60379
Updated by: cataphract@php.net
Reported by: orangejasmine at hotmail dot com
Summary: Cannot access numeric property when object is
created by casting from array
-Status: Assigned
+Status: Duplicate
Type: Bug
Package: *Programming Data Structures
Operating System: Windows XP
PHP Version: 5.3.8
Assigned To: cataphract
Block user comment: N
Private report: N
New Comment:
Duplicate of #45959, which is wont fix. I'll bring the issue to the list.
Previous Comments:
------------------------------------------------------------------------
[2011-11-25 01:03:45] 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 ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60379&edit=1
Thread (2 messages)