Edit report at http://bugs.php.net/bug.php?id=52899&edit=1
ID: 52899 Updated by: [email protected] Reported by: thorn at slonik dot sk Summary: Incorrect array key cast (string to integer) when key > PHP_INT_MAX Status: Open Type: Bug Package: Scripting Engine problem Operating System: Linux 32-bit PHP Version: 5.2.14 Block user comment: N New Comment: Can you give more details about your system? Are you using distro binaries? I can't reproduce this: r...@router:~# php <?php $array['2147483648'] = 3; var_dump($array); var_dump(PHP_INT_MAX); array(1) { ["2147483648"]=> int(3) } int(2147483647) r...@router:~# php -v PHP 5.2.14 (cli) (built: Aug 18 2010 17:16:15) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies r...@router:~# uname -a Linux router 2.4.36 #340 Sun Jul 27 20:07:55 CEST 2008 mips unknown Previous Comments: ------------------------------------------------------------------------ [2010-09-21 11:50:52] thorn at slonik dot sk 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 this bug report at http://bugs.php.net/bug.php?id=52899&edit=1
