Bug #77614 [NEW]: Array: mixed keys problem in foreach loop

From: Date: Wed, 13 Feb 2019 18:04:16 +0000
Subject: Bug #77614 [NEW]: Array: mixed keys problem in foreach loop
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219559@lists.php.net to get a copy of this message
From: shorvat at gmail dot com Operating system: Win 10 & Ubuntu server PHP version: Irrelevant Package: Arrays related Bug Type: Bug Bug description:Array: mixed keys problem in foreach loop Description: ------------ PHP 7.0.10 & 5.6.25 Key comparation in foreach loop not working as expected when keys are of mixed types (strings and ints) If I use triple-equals operator (===) it works just fine, but it seems it should work with double-equals operator (==) as well. Test script: --------------- $array = array(); $array['word'] = "test 1"; $array['0'] = "test 2"; $array['1'] = "test 3"; foreach($array as $k=>$v) { var_dump($k); if($k == "word") { continue; } print_r($v); } Expected result: ---------------- C:\wamp64\www\tst\array_bug.php:10:string 'word' (length=4) C:\wamp64\www\tst\array_bug.php:10:int 0 test 2 C:\wamp64\www\tst\array_bug.php:10:int 1 test 3 Actual result: -------------- C:\wamp64\www\tst\array_bug.php:10:string 'word' (length=4) C:\wamp64\www\tst\array_bug.php:10:int 0 C:\wamp64\www\tst\array_bug.php:10:int 1 test 3 -- Edit bug report at https://bugs.php.net/bug.php?id=77614&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77614&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77614&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77614&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77614&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77614&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77614&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77614&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77614&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77614&r=support Expected behavior: https://bugs.php.net/fix.php?id=77614&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77614&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77614&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77614&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77614&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77614&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77614&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77614&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77614&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77614&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77614&r=mysqlcfg

« previous php.bugs (#219559) next »