Bug #54616 [Opn->Bgs]: in_array return true if the haystack contain 0

From: Date: Wed, 27 Apr 2011 22:18:14 +0000
Subject: Bug #54616 [Opn->Bgs]: in_array return true if the haystack contain 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160403@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54616&edit=1

 ID:                 54616
 Updated by:         rasmus@php.net
 Reported by:        kozo at alphanet dot ro
 Summary:            in_array return true if the haystack contain 0
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   win, linux
 PHP Version:        5.2.17
 Block user comment: N
 Private report:     N

 New Comment:

That's what the 3rd param to the in_array() call is for. 
You are looking for a string in an array of integers. 
(int)'something' == 0 and 0 exists in the array. If you
want a strict check that does a type check as well, set
the strict flag. No bug here.


Previous Comments:
------------------------------------------------------------------------
[2011-04-27 23:45:25] kozo at alphanet dot ro

Description:
------------
The in_array function return true if the haystack have an element with
value 0

Test script:
---------------
if (in_array('something', array(0)) ) {
	echo 'something is in array';
} else {
	echo 'something is NOT in array';
}


if (in_array('something', array(0, 'element1', 'element2')) ) {
	echo 'something is in array';
} else {
	echo 'something is NOT in array';
}


Expected result:
----------------
something is NOT in array

Actual result:
--------------
something is in array


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54616&edit=1


Thread (2 messages)

« previous php.bugs (#160403) next »