Bug #67762 [Com]: in_array evaluates as true when it should not

From: Date: Tue, 05 Aug 2014 14:59:07 +0000
Subject: Bug #67762 [Com]: in_array evaluates as true when it should not
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186982@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67762&edit=1 ID: 67762 Comment by: xjsv24 at gmail dot com Reported by: jv at vip dot ie Summary: in_array evaluates as true when it should not Status: Not a bug Type: Bug Package: *General Issues PHP Version: Irrelevant Block user comment: N Private report: N New Comment: This looks like a bug to me. It breaks the transitive property. if(0 == null) { echo "1<br>"; } if(0 == "meter") { echo "2<br>"; } if(null == "meter") { echo "3<br>"; } Expected result: ---------------- 1 Actual result: -------------- 1 2 Previous Comments: ------------------------------------------------------------------------ [2014-08-04 23:44:16] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Fundamental bugs are easy to find when you don't read the documentation. > Searches haystack for needle using loose comparison unless strict is set. Loose comparison, where "meter" == 0. If you want a strict comparison to get "meter" !== 0 then pass $strict=true. ------------------------------------------------------------------------ [2014-08-04 23:30:53] jv at vip dot ie Description: ------------ --- From manual page: http://www.php.net/function.in-array --- The result will output true, when it should output false. Yup, this is a pretty fundamental bug ;) Test script: --------------- $correct_answers = array('meter'); $my_answer = 0; echo in_array($my_answer, $correct_answers); Expected result: ---------------- false Actual result: -------------- true ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67762&edit=1

« previous php.bugs (#186982) next »