php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52025 Array keys type cast error when use maximum integer value
Submitted: 2010-06-09 02:32 UTC Modified: 2011-11-16 14:05 UTC
From: djmix-2006 at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: djmix-2006 at hotmail dot com
New email:
PHP Version: OS:

 

 [2010-06-09 02:32 UTC] djmix-2006 at hotmail dot com
Description:
------------
Tested on PHP 5.2.9
When trying to check if a key exists into an array, and the key is the standard representation of an integer, php must interpreted as such like the documentation says: (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08")
This don't happens when the value of the key is the same than the maximum value of an integer (PHP_INT_MAX).
Assuming that PHP_INT_MAX is 2147483647, the two lines below will not return true as expected.
isset($array[2147483647]); //true
isset($array['2147483647']); //false

This doesn't happens when key is smaller than the maximum value of an integer.
isset($array[2147483646]); //true
isset($array['2147483646']); //true

Test script:
---------------
<?php
$maxInteger = (int)PHP_INT_MAX;
$keyInt = $maxInteger;
$keyStr = strval($keyInt);

echo "Maximum value is $maxInteger \n";

$arr = array($keyInt => 1);


echo 'Key Integer exists: ' . (int)isset($arr[$keyInt]) . "\n"; //Yes
echo 'Key String exists: ' . (int)isset($arr[$keyStr]) . "\n"; //No

$keyInt = $maxInteger - 1;
$keyStr = strval($keyInt);

echo 'Key Integer exists: ' . (int)isset($arr[$keyInt]) . "\n"; //Yes
echo 'Key String exists: ' . (int)isset($arr[$keyStr]) . "\n"; //Yes


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-09 03:53 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2010-06-09 03:53 UTC] felipe@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I cannot reproduce it on 5.2.14-dev...
 [2010-06-09 04:54 UTC] djmix-2006 at hotmail dot com
-Status: Feedback +Status: Open -PHP Version: 5.2.13 +PHP Version: 5.2.9
 [2010-06-09 04:54 UTC] djmix-2006 at hotmail dot com
No problem on 5.2.13.
Yes on PHP 5.2.9 and PHP 5.2.5
 [2011-11-16 14:05 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-11-16 14:05 UTC] felipe@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC