From:             
Operating system: Windows
PHP version:      5.2.13
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Array keys type cast error when use maximum integer value

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 bug report at http://bugs.php.net/bug.php?id=52025&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52025&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52025&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52025&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52025&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52025&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52025&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52025&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52025&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52025&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52025&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52025&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52025&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52025&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52025&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52025&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52025&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52025&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52025&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52025&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52025&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52025&r=mysqlcfg

Reply via email to