Bug #79941 [NEW]: If statement comparison bug in foreach loop

From: Date: Fri, 07 Aug 2020 05:00:21 +0000
Subject: Bug #79941 [NEW]: If statement comparison bug in foreach loop
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228436@lists.php.net to get a copy of this message
From: wdh at allcode dot io Operating system: CentOS PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Bug Bug description:If statement comparison bug in foreach loop Description: ------------ In the test code, if($k == 'ex') statement is malfunctioning. the statement should be return true only at the 'ex' string, but also return true at the 0. Test script: --------------- $arr = [ 0 => 'a', 1 => 'b', 'ex' => 'c', ]; foreach($arr as $k => $v) { if($k == 'ex') { echo $k; } } Expected result: ---------------- ex Actual result: -------------- 0ex -- Edit bug report at https://bugs.php.net/bug.php?id=79941&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79941&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79941&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79941&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79941&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79941&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79941&r=support Expected behavior: https://bugs.php.net/fix.php?id=79941&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79941&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79941&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79941&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79941&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79941&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79941&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79941&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79941&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79941&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79941&r=mysqlcfg

« previous php.bugs (#228436) next »