Bug #77585 [Com]: in_array wrong answer

From: Date: Fri, 08 Feb 2019 08:22:21 +0000
Subject: Bug #77585 [Com]: in_array wrong answer
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219428@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77585&edit=1 ID: 77585 Comment by: giolaza at gmail dot com Reported by: giolaza at gmail dot com Summary: in_array wrong answer Status: Open Type: Bug Package: *General Issues Operating System: ubuntu PHP Version: 7.2Git-2019-02-08 (Git) Block user comment: N Private report: N New Comment: maybe. this result is because php tries to make same types during checking if(intval($array[0])==$var) because if(0=='string') is true too( but I thing this is wrong; Previous Comments: ------------------------------------------------------------------------ [2019-02-08 08:12:12] giolaza at gmail dot com Description: ------------ in array return true if I am checking 0 var if $var=0; result is wrong int(0) in_array IS TRUE bool(true) $var=(int) 1-1; result is wrong; int(0) in_array IS TRUE bool(true) if $var=1; result is current int(1) in_array IS FALSE bool(false) if $var=NULL; result is current NULL in_array IS FALSE bool(false) if $var=''; result is current string(0) "" in_array IS FALSE bool(false) Test script: --------------- <?php $array=['users','documents','timePunch','vacation','requests']; $var=0; if(in_array($var,$array)){ echo 'in_array IS TRUE'; } else{ echo 'in_array IS FALSE'; } echo PHP_EOL; var_dump(in_array($var,$array)); Expected result: ---------------- in_array IS FALSE bool(false) Actual result: -------------- in_array IS TRUE bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77585&edit=1

« previous php.bugs (#219428) next »