Bug #72254 [Opn]: get_object_vars() returns unusable result when keys are numeric
| From: | yohgaki@php.net | Date: | Mon, 23 May 2016 00:59:21 +0000 |
| Subject: | Bug #72254 [Opn]: get_object_vars() returns unusable result when keys are numeric | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201228@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72254&edit=1
ID: 72254
Updated by: yohgaki@php.net
Reported by: unirgy at gmail dot com
Summary: get_object_vars() returns unusable result when keys
are numeric
Status: Open
Type: Bug
Package: Unknown/Other Function
Operating System: Any
PHP Version: 7.0.6
Block user comment: N
Private report: N
New Comment:
https://3v4l.org/7tshA
PHP 7 behaves like HHVM. PHP 5.6 does not.
Previous Comments:
------------------------------------------------------------------------
[2016-05-23 00:47:09] unirgy at gmail dot com
Description:
------------
If argument in get_object_vars() has numeric keys, the resulting array is built using numeric string
keys, which apparently can't be referenced.
Test script:
---------------
$json = '{"1":"A"}';
$arrWorks = json_decode($json, true);
var_dump($arrWorks);
var_dump($arrWorks[1], $arrWorks['1']);
echo "\n=================\n";
$arrDoesntWork = get_object_vars(json_decode($json));
var_dump($arrDoesntWork);
var_dump($arrDoesntWork[1], $arrDoesntWork['1']);
Expected result:
----------------
array(1) {
[1]=>
string(1) "A"
}
string(1) "A"
string(1) "A"
=================
array(1) {
[1]=>
string(1) "A"
}
string(1) "A"
string(1) "A"
Actual result:
--------------
array(1) {
[1]=>
string(1) "A"
}
string(1) "A"
string(1) "A"
=================
array(1) {
["1"]=>
string(1) "A"
}
Notice: Undefined offset: 1 in /in/bbleq on line 12
Notice: Undefined offset: 1 in /in/bbleq on line 12
NULL
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72254&edit=1