[PHP-BUG] Bug #75880 [NEW]: array key duplicate with integer and string

[email protected] ("mars0222 at gmail dot com") Sat, 27 Jan 2018 10:02:16 GMT
Newsgroups php.standards
Message-ID <[email protected]>
From:             mars0222 at gmail dot com
Operating system: ubuntu:16.04
PHP version:      7.0.27
Package:          PHP Language Specification
Bug Type:         Bug
Bug description:array key duplicate with integer and string

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 bug report at https://bugs.php.net/bug.php?id=75880&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75880&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75880&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75880&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75880&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75880&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75880&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75880&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75880&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75880&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75880&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75880&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75880&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75880&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75880&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75880&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75880&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75880&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75880&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75880&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75880&r=mysqlcfg