Edit report at https://bugs.php.net/bug.php?id=71208&edit=1
ID: 71208
Updated by: [email protected]
Reported by: [email protected]
Summary: Array/Object cast looses numeric property/element
accessibility
-Status: Open
+Status: Assigned
Type: Bug
Package: Scripting Engine problem
Operating System: OS X 10.11 El Capitan
PHP Version: 7.0.1
-Assigned To:
+Assigned To: ajf
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2015-12-23 23:50:41] [email protected]
Description:
------------
If an array is casted to an object, its integer keys become inaccessible integer(!) key properties. They should be normal string key properties instead.
Test script:
---------------
<?php
$arr = [1, 2, 4];
$obj = (object)$arr;
var_dump($obj);
var_dump($obj->{1}, $obj->{2}, $obj->{3});
var_dump($obj->{'1'}, $obj->{'2'}, $obj->{'3'});
?>
Expected result:
----------------
object(stdClass)#1 (3) {
["0"]=>
int(1)
["1"]=>
int(2)
["2"]=>
int(4)
}
int(1)
int(2)
int(4)
int(1)
int(2)
int(4)
Actual result:
--------------
object(stdClass)#1 (3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(4)
}
Notice: Undefined property: stdClass::$1 in - on line 7
Notice: Undefined property: stdClass::$2 in - on line 7
Notice: Undefined property: stdClass::$3 in - on line 7
NULL
NULL
NULL
Notice: Undefined property: stdClass::$1 in - on line 8
Notice: Undefined property: stdClass::$2 in - on line 8
Notice: Undefined property: stdClass::$3 in - on line 8
NULL
NULL
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71208&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.