From:             se...@php.net
Operating system: RHEL 5.3
PHP version:      5.2CVS-2009-03-09 (snap)
PHP Bug Type:     Arrays related
Bug description:  foreach() fails to compare key properly

Description:
------------
Following script will print '4-FAIL' using php 5.2.9 build and today's
snapshot php5.2-200903092130.

Following returns true where $k = int(0), which is wrong:
if ($k == 'abc')
        echo "3-FAIL\n";

Also confirmed this is failing on 5.1.6.


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

$a = array(4);
if ($a[0] != '4')
        echo "1-FAIL";

if ($a[0] != 4)
        echo "2-FAIL";

if ($a[0] == 'abc')
        echo "3-FAIL\n";

foreach ($a as $k => $v)
{
        // $k is ONLY and ALWAYS ZERO (0)
        var_dump($k);
        var_dump($v);

        if ($k == 'abc')
                echo "4-FAIL\n";

        if ($k === 'abc')
                echo "5-FAIL\n";

        if ($v == 'abc')
                echo "6-FAIL\n";
}


Expected result:
----------------
Code should not print anything.
Only key is int(0) and only value is int(4)


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

Reply via email to