|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-09-21 11:50 UTC] 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) } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
Can you give more details about your system? Are you using distro binaries? I can't reproduce this: root@router:~# php <?php $array['2147483648'] = 3; var_dump($array); var_dump(PHP_INT_MAX); array(1) { ["2147483648"]=> int(3) } int(2147483647) root@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 root@router:~# uname -a Linux router 2.4.36 #340 Sun Jul 27 20:07:55 CEST 2008 mips unknown