You Can’t Take True From False, False Is Less than True
or, PHP’s new math
Adam Parrish’s clever post, “Ghost Equals Ghost, but Poison Is False to Steel,” comparing PHP’s type comparison game with Pokémoon’s truth table for a bizarre form of fuzzy logic only scratches the surface when it comes to further insanity in the PHP spec.
Here’s a language where a few simple rules designed for convenience produce disastrous user experience when applied concurrently. The Double Equals Loose Comparison Matrix appears, at first glance, to be an arbitrary construct of a language designer’s twisted, sadistic brain.

After a bit of archeological excavation, we find that there may be method behind the madness. At the very least a lesser lunacy is involved, since the type conversion rules below describe the mechanisms at work behind the seemingly chaotic scattering of Trues and Falses above.

But we do not get off quite so easily. PHP would not allow it. Why is False less than True? (Boolean values shouldn’t have a natural order.) If “array is always greater” when comparing an array to any other type, and “object is always greater” when comparing an object to any other type, what happens when you compare an object to an array? PHP is just a bag of ambiguity.
Jan 4, 2010#programming
