Bug #79941 [Opn]: If statement comparison bug
| From: | wdh at allcode dot io | Date: | Fri, 07 Aug 2020 05:11:46 +0000 |
| Subject: | Bug #79941 [Opn]: If statement comparison bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228438@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
User updated by: wdh at allcode dot io
Reported by: wdh at allcode dot io
-Summary: If statement comparison bug in foreach loop
+Summary: If statement comparison bug
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.
Previous Comments:
------------------------------------------------------------------------
[2020-08-07 05:10:14] wdh at allcode dot io
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
------------------------------------------------------------------------
[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