|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14343 in_array wrongly matches zero
Submitted: 2001-12-04 15:37 UTC Modified: 2002-02-13 17:02 UTC
From: davidw at ensky dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.5 OS: Linux/PPC
Private report: No CVE-ID: None
 [2001-12-04 15:37 UTC] davidw at ensky dot 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'));

If I add the third parameter, it returns the correct 
print in_array(0, array('foobar'), true);

However, I'm pretty sure that 0 doesn't coerce to 'foobar' 
- I don't think PHP is that loosely-typed :)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-04 15:49 UTC]
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.

 [2001-12-04 16:00 UTC] davidw at ensky dot com
Doh! I should have known that.
 [2002-02-13 16:30 UTC] jonas at delfs dot 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.
 [2002-02-14 17:41 UTC] jonas at delfs dot dk
Yes, but a note on 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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 05 05:01:29 2024 UTC