php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: songchao1234 at yeah dot net
New email:
PHP Version: OS:

 

 [2005-12-27 08:39 UTC] 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)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-27 10:38 UTC] tony2001@php.net
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: Sun May 05 14:01:31 2024 UTC