php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75880 array key duplicate with integer and string
Submitted: 2018-01-27 10:02 UTC Modified: 2018-01-27 10:06 UTC
From: mars0222 at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.27 OS: ubuntu:16.04
Private report: No CVE-ID: None
 [2018-01-27 10:02 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-27 10:06 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: PHP Language Specification +Package: Scripting Engine problem -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC