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

From: Date: Fri, 07 Aug 2020 05:10:14 +0000
Subject: Bug #79941 [Com]: If statement comparison bug in foreach loop
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228437@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79941&edit=1 ID: 79941 Comment by: wdh at allcode dot io Reported by: wdh at allcode dot io Summary: If statement comparison bug in foreach loop Status: Open Type: Bug Package: Scripting Engine problem Operating System: CentOS PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Not only in the foreach loop, the If statement produce the bug. Test script: --------------- $str = 'ex'; if($str == 0) { echo $str; } Expected result: ---------------- (no output) Actual result: -------------- ex Previous Comments: ------------------------------------------------------------------------ [2020-08-07 05:00:21] wdh at allcode dot io 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 this bug report at https://bugs.php.net/bug.php?id=79941&edit=1

« previous php.bugs (#228437) next »