Bug #14343 Updated: in_array wrongly matches zero
| From: | jonas at delfs dot dk | Date: | Thu, 14 Feb 2002 22:41:37 +0000 |
| Subject: | Bug #14343 Updated: in_array wrongly matches zero | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-330@lists.php.net to get a copy of this message | ||
ID: 14343
Updated by: jonas@delfs.dk
-Reported By: davidw@ensky.com
+Reported By: jonas@delfs.dk
Status: Bogus
Bug Type: Arrays related
Operating System: Linux/PPC
PHP Version: 4.0.5
New Comment:
Yes, but a note on http://php.net/in_array would save some
people's
time, I think.
At this point I've committed a user-note - hopefully this will save
_some_ of the people from going insane.
Previous Comments:
------------------------------------------------------------------------
[2002-02-13 17:02:27] torben@php.net
We did, years ago.
http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion
Torben
------------------------------------------------------------------------
[2002-02-13 16:30:12] jonas@delfs.dk
It would be very nice if you guys would document this "feature" so
people like me don't spend too much valueable time on such a thing.
------------------------------------------------------------------------
[2001-12-04 16:00:21] davidw@ensky.com
Doh! I should have known that.
------------------------------------------------------------------------
[2001-12-04 15:49:37] derick@php.net
Not a bug... PHP indeed tries to convert 'foobar' to a number, and
because that is not really possible, it becomes 0. That's why there is
that third parameter too.
Derick
------------------------------------------------------------------------
[2001-12-04 15:37:18] davidw@ensky.com
On my system, in_array wrongly returns true when searching
for zero in arrays that don't contain zero:
Sample code:
in_array(0, array('foobar'));
-->TRUE
If I add the third parameter, it returns the correct
result:
print in_array(0, array('foobar'), true);
-->FALSE
However, I'm pretty sure that 0 doesn't coerce to 'foobar'
- I don't think PHP is that loosely-typed :)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=14343&edit=1