If you're used to languages with intelligent logical operators, you will try to do things like:
$iShouldTalkTo = $thisObj || $thatObj;
In PHP, $iShouldTalkTo
is now a boolean value. You're forced to write:
$iShouldTalkTo = $thisObj ? $thisObj : $thatObj;
Out of all the examples of how early design decisions in PHP tried to hold the hands of incompetent programmers in exchange for hobbling competent ones, that may be the one that irritates me the most.
Deep brain-damage in the switch()
construct abounds. Consider this:
switch($someVal) {
case true :
doSomething();
break;
case 20 :
doSomethingElse();
break;
}
Turns out that doSomethingElse()
will never be called, because 'case true' will absorb all true cases of $someVal.
Think that's justifiable, perhaps? Well, try this one:
for($ix = 0; $ix < 10; $ix++) {
switch($ix) {
case 3 :
continue;
default :
echo ':';
}
echo $ix;
}
Guess what its output is? Should be :0:1:2:4:5:6:7:8:9, right? Nope, it's :0:1:23:4:5:6:7:8:9. That is, it ignores the semantics of the continue
statement and treats it as a break
.