We're using pseudo-code to /r/lolphp about the language's lovely capacity to make wild-ass guesses about what variables should evaluate to when placed in various type-casting situations.
Any sane language (even JavaScript, for most situations not going from <something> -> boolean) will instead politely tell you to GTFO.
See, this is the problem. It's not real code. Without any explanation beside it, I have no idea what you think a reasonable result is, or what PHP to translate it to inside my head.
Although I am aware of those non-transitivity party tricks where each individual comparison along the chain is X, while comparing each end directly is !X, this doesn't hold in this case. I'm unable to develop valid PHP code in which "php" compares as equal to "0", null, or false. (0 and 0.0 are equal, though.)
Is this really that difficult of a thing to understand? When you use == it does automatic type conversion which is why you get weird results sometimes, this behavior is well documented and believe it or not it actually makes sense for a loose comparison+type conversion.
If you don't want any of this, use ===, wow so difficult.
Exactly. In the cases where you should be using ==, the conversions are generally helpful and intuitive. The cases where they aren't are the cases where you should have been using === anyway.
If it helps, think of === as the standard equality operator, and == is more like a shortcut operator that saves some manual type logic and conversion work. Like any shortcut, you should understand what it does before you use it.
24
u/[deleted] Mar 26 '14
Or, the definition of insanity.