Edit report at https://bugs.php.net/bug.php?id=70835&edit=1
ID: 70835
Updated by: [email protected]
Reported by: phpbugs at elygor dot de
Summary: array cast returns unusable index
Status: Open
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
It's even worse in PHP 7: get_object_vars() also produces an array with inaccessible indices.
Previous Comments:
------------------------------------------------------------------------
[2015-11-02 11:34:36] phpbugs at elygor dot de
Description:
------------
Converting a stdClass object with (array) behaves different than get_object_vars()
I tested this with PHP 5.4.45 5.5.18 and 5.6.2
Test script:
---------------
$tmp = json_decode(json_encode(
(object) array('cars' => (object) array("1" => "one"))
));
// expected $cars = array("1" => "one");
$cars = (array) $tmp->cars;
var_dump(array_key_exists("1", $cars)); // expected true, returns false
var_dump(array_key_exists(1, $cars)); // expected true, returns false
$cars = get_object_vars($tmp->cars);
var_dump(array_key_exists("1", $cars)); // expected true, returns true
var_dump(array_key_exists(1, $cars)); // expected true, returns true
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70835&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.