|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35813 arrays problem
Submitted: 2005-12-27 08:39 UTC Modified: 2005-12-27 10:38 UTC
From: songchao1234 at yeah dot net Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.1.1 OS: redhat 7.3
Private report: No CVE-ID: None
 [2005-12-27 08:39 UTC] songchao1234 at yeah dot net
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:
$max=mt_getrandmax();  //2147483647
$arr=array($max=>1);   //first
$arr[]=2;              //second
$arr[]=3;              //third
$arr[]=4;              //forth

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) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-27 10:38 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 22:01:33 2024 UTC