Up until a few weeks ago, I had used PHP only a handful of times, generally when tinkering with WordPress. That was up until I started my current job, maintaining a terrible content management “system” written in a mixture of PHP and perl.

What kicked this client from “suck” to “kill me now” was having to deal with PHP. I hate this language. So. Much. The office can tell when I’m working on this project from the stream of profanity alone.

The current version of my “Why PHP is destroying my soul little by little” list:

  • You can’t write something like get_active_subscription($user)->subscription_type. You first have to assign the return value of get_active_subscription() to an intermediate variable, then grab the subscription_type attribute from that intermediate. The same thing goes for array subscription.

  • PHP’s three billion functions were named by someone on psychotropic drugs. As evidence: count v strlen v count_chars v str_word_count. Quick — what’s the difference?

  • $some_object->nonexistant_attribute evaluates to the empty string.

  • $misspelled_variable evaluates to the empty string.

  • Pushing a value on to an array is spelled $arr[] = $object. You’re right, that is better than a function (perl’s push @array, $object) or a method (python’s list.append(object)).

  • The incredibly consistent naming scheme for functions. My favorite examples are the array_* and *_array functions.

  • My absolute favorite comes from the PHP manual, talking about why you shouldn’t use barewords to index an array, i.e., $foo[bar] instead of $foo["bar"]:

    [Using a bareword] is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string. and PHP may in future define constants which, unfortunately for your code, have the same name. It works because PHP automatically converts a bare string (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named bar, then PHP will substitute in the string ‘bar’ and use that.

    Brilliant.

  • You can use return outside of functions without PHP complaining.

  • The entire array() class. Everything about it. Absolutely everything. I’ve been using it for a month, and I still don’t feel comfortable with the thing’s semantics.

  • From the docs for array_diff(): “Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.”

    Best. Equivalence test. Ever.

  • Writing $a = $b || $c gives you a boolean, not the value of $b or $c like some more useful languages I can think of.

I’m still debating what conclusion to draw about PHP. I can’t decide whether it’s the diseased creation of a bunch of retards gone off their meds, or if it’s one of the most successful and widespread practical jokes ever conceived (”Let’s see how many people we can get to use this piece of shit!” “Dude, that’s awesome!”).