Bug #75880 [Opn->Csd]: array key duplicate with integer and string
| From: | nikic@php.net | Date: | Sat, 27 Jan 2018 10:06:55 +0000 |
| Subject: | Bug #75880 [Opn->Csd]: array key duplicate with integer and string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213721@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75880&edit=1
ID: 75880
Updated by: nikic@php.net
Reported by: mars0222 at gmail dot com
Summary: array key duplicate with integer and string
-Status: Open
+Status: Closed
Type: Bug
-Package: PHP Language Specification
+Package: Scripting Engine problem
Operating System: ubuntu:16.04
PHP Version: 7.0.27
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed in 7.2, see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts.
Previous Comments:
------------------------------------------------------------------------
[2018-01-27 10:02:13] mars0222 at gmail dot com
Description:
------------
When use (array) to convert the object to array, the key will using string even the it is integer,
then the string key will never been get.
Test script:
---------------
$obj = '{"300": {"id": "foo"}}';
$obj = json_decode($obj);
$obj = (array)$obj;
var_dump($obj); // array (size=1) '300' => string 'foo' (length=3)
var_dump($obj["300"]); // null
var_dump($obj[300]); // null
Expected result:
----------------
It should be convert the object key to integer if it can convert to integer.
Actual result:
--------------
When convert the object the key will always be string even the key can convert to integer.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75880&edit=1