Chris Warburton

Chris Warburton at

I've been irked all day by the line "if ($foo == 1) {...}" and finally spotted the problem; it's not that the author's been too lazy to put an extra "=" on their comparison, it's that they've done a comparison at all!
According to PHP's type-mangling, "1" is 'truthy', so "if ($foo == 1) {...}" is pretty much like "if ($foo == TRUE) {...}". Hopefully it's obvious to everyone what's wrong with that: "if" casts its condition to a boolean and checks if it's TRUE, so this *isn't lazy enough*! We can just do "if ($foo) {...}"

*I say "the line" but of course this pattern is actually copy-pasted a few times in a row, since it never occurred to the author to use a loop...