php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45877 Array key '2147483647' left as string
Submitted: 2008-08-21 03:04 UTC Modified: 2009-05-14 01:45 UTC
From: henryptung at gmail dot com Assigned: mattwil (profile)
Status: Closed Package: Arrays related
PHP Version: 5.2.6 OS: CentOS 4
Private report: No CVE-ID: None
 [2008-08-21 03:04 UTC] henryptung at gmail dot com
Description:
------------
I believe '2147483647' (= 2^31 - 1) should be the standard representation of a valid integer, but using the string form as an array key stores the key as a string, not an integer.  The integer key 2147483647 can be used separately to refer to a different value, and both are stored.  See repro code below:

Note: this bug is admittedly duplicate of bug #13407, but the bug still exists, and I fail to understand why the original bug was marked bogus.  Thanks for your time.

Reproduce code:
---------------
$v = array('2147483647' => 'b', '2147483646' => 'c', 2147483647 => 'd');
var_dump($v);

Expected result:
----------------
array(2) {
  [2147483647]=>
  string(1) "d"
  [2147483646]=>
  string(1) "c"
}

Actual result:
--------------
array(3) {
  ["2147483647"]=>
  string(1) "b"
  [2147483646]=>
  string(1) "c"
  [2147483647]=>
  string(1) "d"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-21 07:18 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

use a 64bit machine for big integers
 [2009-03-17 18:45 UTC] mattwil@php.net
I had also noticed this issue awhile back. Finally created a simple fix so it works consistently and as expected, and will apply it soon, hopefully.

http://realplain.com/php/array_key_limit.diff
http://realplain.com/php/array_key_limit_5_3.diff
 [2009-03-18 01:12 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.

Just fixed in 5.3 for now.
 [2009-05-14 01:45 UTC] mattwil@php.net
Also fixed in 5.2 now. See Bug #48254.
 [2010-10-05 13:29 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&revision=304083
Log: Fixed bug #51008 (Zend/tests/bug45877.phpt fails)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 11:01:27 2024 UTC