Bug #52899 [NEW]: Incorrect array key cast (string to integer) when key > PHP_INT_MAX
| From: | thorn at slonik dot sk | Date: | Tue, 21 Sep 2010 09:50:53 +0000 |
| Subject: | Bug #52899 [NEW]: Incorrect array key cast (string to integer) when key > PHP_INT_MAX | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-154526@lists.php.net to get a copy of this message | ||
From:
Operating system: Linux 32-bit
PHP version: 5.2.14
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Incorrect array key cast (string to integer) when key > PHP_INT_MAX
Description:
------------
When using string as an array's key which looks like integer - the key is
converted to integer. That is ok for integers not bigger than PHP_INT_MAX.
But when the key is: PHP_INT_MAX < key < 3000000000 (on 32-bit system)
the key is converted to incorrect integer (it overflows :)
The key should remain string and not be converted to incorrect int.
See test script, expected and actual results.
Doc:
http://www.php.net/manual/en/language.types.array.php
A key may be either an integer or a string. If a key is the standard
representation of an integer, it will be interpreted as such (i.e. "8" will
be interpreted as 8, while "08" will be interpreted as "08").
Related bugs:
#51430
#48254
#52025
Test script:
---------------
$array['2000000000'] = 1; // ok
$array['2147483647'] = 2; // ok
$array['2147483648'] = 3; // incorrect
$array['2999999999'] = 4; // incorrect
$array['3000000000'] = 5; // ok again
var_dump($array);
Expected result:
----------------
array(5) {
[2000000000]=>
int(1)
[2147483647]=>
int(2)
["2147483648"]=>
int(3)
["2999999999"]=>
int(4)
["3000000000"]=>
int(5)
}
Actual result:
--------------
array(5) {
[2000000000]=>
int(1)
[2147483647]=>
int(2)
[-2147483648]=> // int key overflow
int(3)
[-1294967297]=> // int key overflow
int(4)
["3000000000"]=>
int(5)
}
--
Edit bug report at http://bugs.php.net/bug.php?id=52899&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52899&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52899&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52899&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52899&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52899&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52899&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52899&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52899&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52899&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52899&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52899&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52899&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52899&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52899&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52899&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52899&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52899&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52899&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52899&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52899&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52899&r=mysqlcfg