In PHP ==
contains a whole new dimension of WTF compared to Javascript ==
. For example, in PHP, ==
will actually
parse strings for numbers and compare those, so for example, in PHP "000" == "0"
is true
. In Javascript that is false
because they are obviously 2 different strings by any rational definition of string equality.
As for Javascript ==
in general, the rules for it are surprisingly simple if you read the actual rules for them in the specification (I still won't use it because the average joe obviously doens't read specs). In PHP I would always use ===
because there is no specification - just ad hoc examples of comparisons. I had to read about the string parsing in PHP source code for example.
Another really fun effect of the PHP ==
string parsing is that if the string cannot be parsed into machine integer, it will just be compared as string. So the same equality comparison can give different results depending on whether the PHP runs under 32-bit or 64-bit. Fun times.