|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-29 20:18 UTC] 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
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
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/LinuxHere is the info from the original 32bit machine that also sees the bug in 5.3.3-dev: # ./php -v PHP 5.3.3-dev (cli) (built: Jun 11 2010 09:48:12) 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 # gcc -v Using built-in specs. Target: i686-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man -- infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla -- enable-bootstrap --enable-shared --enable-threads=posix --enable- checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind- exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj- c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin -- with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar -- disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with- arch=i686 --build=i686-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC)