php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48254 Inconsistent handling of huge numerical keys for array
Submitted: 2009-05-13 03:47 UTC Modified: 2009-05-14 01:42 UTC
From: for-bugs at hnw dot jp Assigned: mattwil
Status: Closed Package: Arrays related
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID:
 [2009-05-13 03:47 UTC] for-bugs at hnw dot jp
Description:
------------
There is inconsistency in dealing with huge numerical array key.

We know PHP normalizes array key with numerical string to integer if possible. For instance, $a["1"] is equevalent to $a[1]. However, it is not valid about PHP_INT_MAX and ~PHP_INT_MAX (2147483647 and -2147483648 in 32bit envirionment).

Reproduce code:
---------------
<?php

$a[PHP_INT_MAX]=1;
$a[(string)PHP_INT_MAX]=2;
var_dump($a);

Expected result:
----------------
array(2) {
  [2147483647]=>
  int(2)
}

Actual result:
--------------
array(2) {
  [2147483647]=>
  int(1)
  ["2147483647"]=>
  int(2)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-13 14:25 UTC] mattwil@php.net
See Bug #45877.

This has been fixed in PHP 5.3. I didn't backport the change to 5.2 since it's been around forever and didn't know if the fix would be wanted in 5.2 (primarily by who's in charge of it) at this point in its lifecycle.

I'll leave this open for now to see if other devs have a comment...
 [2009-05-13 18:40 UTC] jani@php.net
Matt, bug fixes should go into PHP_5_2. And I guess this is the same 
patch needing MFB to HEAD too? :)
 [2009-05-14 01:42 UTC] mattwil@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Taken care of now!

I know, Jani, and I've merged other fixes. :-) Just thought this might be considered, by others, more of a "feature change," since previous bug reports had been dismissed. And Dmitry, nor anyone else, said anything about including 5.2 when the change was made in HEAD/5.3 2 months ago...

Nope, this has nothing to do with the other part missing from HEAD. ;-) Even though I didn't personally commit this fix, it was done in HEAD as well. (I've changed the reported version back to 5.2.9)
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 07:02:02 2014 UTC