Req #75053 [NEW]: Integer array key limitations
| From: | bryanp at healthendeavors dot com | Date: | Tue, 08 Aug 2017 22:26:09 +0000 |
| Subject: | Req #75053 [NEW]: Integer array key limitations | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-210562@lists.php.net to get a copy of this message | ||
From: bryanp at healthendeavors dot com
Operating system: Windows 2008 server
PHP version: 5.6.31
Package: Math related
Bug Type: Feature/Change Request
Bug description:Integer array key limitations
Description:
------------
Casting large numbers to integers as array keys leads to unexpected
results that are not obvious when looking at the code. It appears the
32-bit integer limit is being reached.
Casting the key to a string or triggering an error letting the user know
something went wrong would be more helpful.
I think it's much more useful to have the wrong type than the wrong
value as the key. Additionally, casting to an integer has a chance to
replace an existing key.
Releated bugs: 51430 shows as duplicate of 51008 which shows a status of
Closed and says fixed.
Test script:
---------------
$arr = [1410065407 => 'some value'];
$arr[9999999999] = 'another value';
var_dump($arr);
Expected result:
----------------
array (size=2)
1410065407 => string 'some value' (length=10)
'9999999999' => string 'another value' (length=13)
Actual result:
--------------
array (size=1)
1410065407 => string 'another value' (length=13)
--
Edit bug report at https://bugs.php.net/bug.php?id=75053&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75053&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75053&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75053&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75053&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75053&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75053&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75053&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75053&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75053&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75053&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75053&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75053&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75053&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75053&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75053&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75053&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75053&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75053&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75053&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75053&r=mysqlcfg