Bug #64376 [Opn->Nab]: Comparison does not return correct value
Edit report at https://bugs.php.net/bug.php?id=64376&edit=1
ID: 64376
Updated by: rasmus@php.net
Reported by: ludko2 at gmail dot com
Summary: Comparison does not return correct value
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Programming Data Structures
Operating System: win7 64bit
PHP Version: 5.4.12
Block user comment: N
Private report: N
New Comment:
You are comparing a string to an int. Both sides are cast to int. (int)"b0123..."
cast to an integer is 0. 0==0.
Use === to force a strict comparison, or explicitly cast your operands to your
desired type.
Previous Comments:
------------------------------------------------------------------------
[2013-03-07 12:08:45] ludko2 at gmail dot com
Description:
------------
Comparison between string and zero and string returns true?!?
var_dump("b0180e6574921b8b8de3c40bfd046571"==0);
tested on 5.4.6 win 7 64bit
Test script:
---------------
$arr = array("0"=>"b");
var_dump($arr);//array(1) { [0]=> string(1) "b"}
foreach($arr as $k=>$v){
var_dump($k == "c"); // returns true (FAIL)
}
var_dump("b"==0);//returns true (FAIL)
var_dump("a"==1); // returns false (OK)
Expected result:
----------------
var_dump("b"==0);// expecting false
Actual result:
--------------
var_dump("b"==0);// returning true
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64376&edit=1
Thread (6 messages)