If (0 == '%') echo "WTF, Php, why can't you compare things great?"

I just reduced the crazy mistake to what's in the title of this question. I am sure there is a perfectly reasonable explanation for why Php considers 0 == '%' (or any other special character, I think). I thought it would be nice to get this explanation on StackOverflow!

+5
source share
4 answers

Using '===' (for an exact, literal comparison - the values ​​must be of the same type and also equal) instead of '==' solves this problem. With '==', he is trying to distinguish '%' from a number, and 0 is the best he can do.

+6

, 0.

+7

, , , , strcmp(). , , , int. , , , strcmp() .

php . ( ), . http://www.php.net/manual/en/types.comparisons.php

+1

"%" , (0), , , 0 == '%'

;-) ,

0

All Articles