Bug #77585 [NEW]: in_array wrong answer

From: Date: Fri, 08 Feb 2019 08:12:12 +0000
Subject: Bug #77585 [NEW]: in_array wrong answer
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219427@lists.php.net to get a copy of this message
From:             giolaza at gmail dot com
Operating system: ubuntu
PHP version:      7.2Git-2019-02-08 (Git)
Package:          *General Issues
Bug Type:         Bug
Bug description:in_array wrong answer

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 bug report at https://bugs.php.net/bug.php?id=77585&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77585&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77585&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77585&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77585&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77585&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77585&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77585&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77585&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77585&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77585&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77585&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77585&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77585&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77585&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77585&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77585&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77585&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77585&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77585&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77585&r=mysqlcfg



Thread (6 messages)

« previous php.bugs (#219427) next »