Bug #30036 [Com]: In_Array not works when array contain booleans
| From: | miker at yahoo-inc dot com | Date: | Fri, 14 Jan 2011 23:53:18 +0000 |
| Subject: | Bug #30036 [Com]: In_Array not works when array contain booleans | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157925@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=30036&edit=1
ID: 30036
Comment by: miker at yahoo-inc dot com
Reported by: marek at lewczuk dot com
Summary: In_Array not works when array contain booleans
Status: Bogus
Type: Bug
Package: Arrays related
Operating System: Windows
PHP Version: 4.3.8
Block user comment: N
Private report: N
New Comment:
sniper@php.net, can you describe the reasoning behind this behavior?
Currently, I'm inclined to agree with Marek that this is bug-like
behavior. Thank you. Mike.
Previous Comments:
------------------------------------------------------------------------
[2004-09-15 11:36:33] marek at lewczuk dot com
Right, it works with 3rd parameter, but it is not the point - is string
"test" equal to boolean "true" ? Even if we are not comparing variable
types, then "test" is not equal to "1". For example, I have an array
with strings, integers, boolean - I'm looking for any "123" value - I
don't care if this is an integer or string - the value is important. In
this case, I can't use in_array with 3rd parameter, because it will not
find all all correct values.
examples:
in_array('232', array(232, '232', true))
this will return true - correct
in_array('232', array(232, true), true)
this will return false - correct
in_array('232', array(233, '233', true))
this will return true - wrong
In my opinion this is not correct behavior...
------------------------------------------------------------------------
[2004-09-15 10:56:57] sniper@php.net
Use the 3rd optional parameter (for strict search) which makes
in_array() to check the type too. NOT a bug.
------------------------------------------------------------------------
[2004-09-09 10:04:27] marek at lewczuk dot com
Description:
------------
When you have an array with boolean values, then in_array will always
return true.
Reproduce code:
---------------
print in_array("test it", array(true, true, "sdsd" => true))
Expected result:
----------------
should return false
Actual result:
--------------
true
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=30036&edit=1