

When 0 == absolutely-any-value-in-the-world in PHP - jv22222
https://bugs.php.net/bug.php?id=67762

======
jv22222
$needle = 0;

$haystack = array('absolutely-any-value-in-the-world');

if ( in_array($needle, $haystack) ) {

echo "I've heard of loose comparison but this might be a little excessive.";

}

Note: I submitted it as a bug on php.net and the response was...

"Fundamental bugs are easy to find when you don't read the documentation."

(Just in case this isn't clear, it was closed as NOT being a bug within 10
mins of submitting.)

Of course I did read the docs and was aware of the strict comparison but I
don't want strict comparison I just want it to work as expected, ie the value
on the left matches the value in an array as long as it looks the same. So I
would expect.. 0 to match '0', or 12345 to match '12345' but would not expect
0 to match any string value.

~~~
krapp
I agree with you - this is the sort of thing where you would expect strict
comparison by default. Either it's in the array or it isn't. And I don't think
i've ever used the strict comparison flag so now I have to go check all my
projects...

 _dammit PHP..._

------
mahadazad
This is not a bug if you read the documentation carefully.

[http://php.net/function.in-array](http://php.net/function.in-array)

~~~
eevee
So if it's documented, it's not a bug? Oh man I'm about to save so much time.

------
bricss
Its a bug of a century!!!

------
mattbillenstein
I've always thought php was insane and should never be used to write any sort
of software...

