Bug #52025 [Opn->Bgs]: Array keys type cast error when use maximum integer value
| From: | felipe@php.net | Date: | Wed, 16 Nov 2011 14:05:58 +0000 |
| Subject: | Bug #52025 [Opn->Bgs]: Array keys type cast error when use maximum integer value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165238@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52025&edit=1
ID: 52025
Updated by: felipe@php.net
Reported by: djmix-2006 at hotmail dot com
Summary: Array keys type cast error when use maximum integer
value
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows
PHP Version: 5.2.9
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-06-09 04:54:14] djmix-2006 at hotmail dot com
No problem on 5.2.13.
Yes on PHP 5.2.9 and PHP 5.2.5
------------------------------------------------------------------------
[2010-06-09 03:53:12] 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 02:32:01] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52025&edit=1