#35813 [Opn->Bgs]: arrays problem
ID: 35813
Updated by: tony2001@php.net
Reported By: songchao1234 at yeah dot net
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: redhat 7.3
PHP Version: 5.1.1
New Comment:
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same.
Thank you for your interest in PHP.
Dup of bug #28972.
Previous Comments:
------------------------------------------------------------------------
[2005-12-27 08:39:05] songchao1234 at yeah dot net
Description:
------------
as php manual says about array:
As of PHP 4.3.0, the index generation behaviour described above has
changed. Now, if you append to an array in which the current maximum
key is negative, then the next key created will be zero (0). Before,
the new index would have been set to the largest existing key + 1, the
same as positive indices are.
so here is the problem:
Reproduce code:
---------------
<?php
$max=mt_getrandmax(); //2147483647
$arr=array($max=>1); //first
$arr[]=2; //second
$arr[]=3; //third
$arr[]=4; //forth
var_dump($arr);
?>
so, according to php manual,
"$arr[]=2" return "[-2147483648]=>int(2)",now, There is two options:
1. suppose that -2147483648(int)<2147483647(int) so, 2147483647 is
still current maximum key, so $arr[]=3; should return
"[-2147483648]=>int(3)", and will overwrite $arr[]=2;
2. -2147483648>2147483647, as manual says, $arr[]=3 should return
"[0]=>3"
Actual result:
--------------
array(4) {
[2147483647]=>
int(1)
[-2147483648]=>
int(2)
[-2147483647]=>
int(3)
[-2147483646]=>
int(4)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35813&edit=1
Thread (2 messages)