Edit report at http://bugs.php.net/bug.php?id=51430&edit=1
ID: 51430
User updated by: will at flourishlib dot com
Reported by: will at flourishlib dot com
Summary: Numeric string array key is being implicitly cast to
32bit int and overflowing
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Fedora 12
PHP Version: 5.3.2
New Comment:
On my 32bit Fedora 12 box this does occur with 5.3.2. That seems to
suggest me a
32/64bit issue. Below is the output:
# php -v
PHP 5.3.2 (cli) (built: Apr 27 2010 17:55:02)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
# php -r 'print_r(array("-2147483649" => TRUE, "-2147483648" =>
FALSE));'
Array
(
[2147483647] => 1
[-2147483648] =>
)
# uname -a
Linux vm-fedora 2.6.31.12-174.2.22.fc12.i686.PAE #1 SMP Fri Feb 19
19:10:04 UTC
2010 i686 i686 i386 GNU/Linux
Previous Comments:
------------------------------------------------------------------------
[2010-06-08 14:27:40] [email protected]
Not reproducible with 5.3.2, 5.3.3-dev and trunk on 64bit Linux.
------------------------------------------------------------------------
[2010-03-29 20:18:41] will at flourishlib dot com
Description:
------------
When trying to use a string array key that contains a number outside of
the 32bit integer range, the key is being cast to an integer implicitly
by PHP and is overflowing the 32bit integer limits.
This incorrect casting is present in both 5.3.1 and 5.3.2 (probably
5.3.0), however 5.1.6 through 5.2.13 do not perform this implicit
casting. The manual indicates that an integer-like key will be cast to
an integer, however that should not be the case when the integer will
not losslessly cast, since that can cause keys to be overwritten.
Test script:
---------------
print_r(array("-2147483649" => TRUE, "-2147483648" => FALSE));
print_r(array("-2147483649" => 1, "-2147483648" => 2, "2147483647" => 3,
"2147483648" => 4));
Expected result:
----------------
Array
(
[-2147483649] => 1
[-2147483648] =>
)
Array
(
[-2147483649] => 1
[-2147483648] => 2
[2147483647] => 3
[2147483648] => 4
)
Actual result:
--------------
Array
(
[2147483647] => 1
[-2147483648] =>
)
Array
(
[2147483647] => 3
[-2147483648] => 4
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51430&edit=1