I think PHP sucks, but not for the obvious reasons. Today I got into a mild discussion on twitter, sparked by the following tweet:

Every time someone says "PHP sucks" an elephpant laughs and keeps counting their money earned from getting things done — (((Chris Hartjes))) (@grmpyprogrammer) June 15, 2016

It’s a nice sentiment, and worth analyzing a bit, but first… a little bit of context:

My background

I’m a PHP developer. I originally started with PHP in the early 2000’s. At that point my main exposure to programming was Pascal, and I started learning C.

Then somebody told me to take a look at PHP, and was I immediately sold on how easy it was to get a dynamic, mysql-backed website out into the world.

The code I wrote back in the day was as awful as you might expect, but I kept going, and here we are, writing PHP nearly half my life. I’m pretty good at it, and used it as the main technology for perhaps a 100 projects, some of which never leaving my computer and others that have turned into successful businesses, with millions of users and one of which resulted in an exit.

I’m active in the PHP community, as a blogger and, (ex-)member of PHP-FIG (which is PHP’s version of Pythons PEP) and have spoken at a few conferences. I’m the author of a widely deployed open-source library. PHP is one of the few things I consider myself an expert in. I think I know almost every obscure detail of the language. (Did you know echo b"foo"; is valid?).

PHP’s reputation

Whenever a discussion starts that involves PHP, on Twitter, Hackernews or Reddit or real life, it usually quickly devolves in a barrage of criticism.

Some of this is unqualified. Doing a quick search on reddit for “PHP” on /r/programming, shows that it is almost universally in a negative context.

Some of this is justified. Yes, PHP has a sloppy standard library, Yes, there is a lot of bad PHP code out there. The language itself is kind of cobbled together and things can be a bit inconsistent. Streams suck! It sucks that every HTTP request is a whole new instance of my PHP application.

Search for “PHP” and “MySQL” on Stackoverflow and you’ll see many people showing samples of code with SQL injection. There was a interesting discussion on the low quality of PHP questions on stackoverflow recently.

A big part of this issue is that the barrier to entry in PHP is so damn low, almost everyone can start hacking wordpress templates. For many people, PHP is the first programming language they try without formal education.

For me, it doesn’t actually matter that much

The big reason a lot of PHP developers get defensive when it comes to this type of criticism, is that they are personally not really affected by it.

We spend most of our time glueing API’s together, and the odd inconsistencies in the standard library are either memorized or not an issue because we use the really good auto-completion tools or we rarely touch them. Our best practices are centered around taking advantage of PHP, the way PHP is.

Our code is mostly secure, automated testing is everywhere and there’s a lot of innovation happening. Our code is closer to Java than it is to Wordpress, and the ecosystem, libraries and frameworks we use have a much greater influence on your day-to-day decisions than the underlying language.

We’ll tell you that over 50% of the web is built in PHP, Facebook uses it sucessfully and has even gone as far as making a new, faster PHP implementation. We might tell you we’re paying our bills with PHP, we’re successful with PHP, love the commmunity, love the new wave of PHP, fueled by composer and those things would all be correct.

I’m a “getting the job done” kind of person and I live by the ideas of “Worse is Better”, so PHP is a great fit for that. I would recommend many new people who have a new business idea to start prototyping with PHP, because it’s simple and pretty easy (and cheap!) to find developers for.

Why PHP sucks

Even if all those things are true, if you put PHP next to a language like Ruby, it will not win the beauty competition. If you put it next to Java, it’s a lot weirder and a lot less “correct”.

If you just look at the language, I think it fine to say “PHP is worse than Java, Ruby, Python, and many others”. If you’re just pitting the merits of the PHP language against almost any other popular language, it will likely lose. PHP is generally not approved in the enterprise, regardless of how hard Zend will try to convince you otherwise. I noticed a pattern of people running Drupal, being surprised it’s built in PHP.

So the critics are right, and so are PHP developers. Any discussion that has the slightest bit of nuance will get to that conclusion.

The problem I have with PHP has nothing to do with the language, it’s its reputation. I can’t count the times I’ve started a conversation with a programmer who upon finding out I primarily do PHP got awkward with me.

Sometimes people are more straightforward and will just respond with “Oh, I’m sorry about that”. Recently I talked to a CEO who more carefully said “Ah, that’s pretty old school right?”. Developers who more-so live in the Java-dominant corporate bubble will likely silently dismiss me as a incompetent programmer.

I hate it, because it makes me feel defensive. PHP in their minds is much worse than it practically is. I’m tired of defending PHP, I’m tired of being set back and having to proof my competence by virtue of being a PHP programmer.

We’re not taken as seriously, and we’re being paid less. The 2016 StackOverflow Survey puts PHP developers as the least paid. Hilariously that position is shared with “LAMP” and “Wordpress”, both of which are also PHP. We’re also among the “most dreaded”.

So what’s next for me?

I’m moving on to a new language. The easy thing will be to learn the language. What’s a bit harder is to learn the ins and outs of the ecosystem.

The hardest by far will be to get to a point where I can with confidence determine why library X is better than library Y, and build up a new reputation in a new community. This is frustrating, but the best time to plant a tree is 20 years ago, the second best time is today.

As for PHP. I will continue to be excited to maintain my open source libraries, but when somebody asks me in the future what I use for programming, the answer might be: “mostly Golang”.

And to anyone considering programming as a career, or trying to get into it… stay away from PHP. There’s lots of fun, interesting languages out there that also get the job done quick, but with a better reputation and this will have an actual effect on your future career options.

Since this getting a lot of traction, I want to address some of the common feedback:

I’m not a single language programmer, but my past has simply set me on a course that made PHP dominant. A big part of this is an open source application that took off and became pretty successful. I would say most of the stuff I’ve done in the last 5 years is related to that product. I’m very grateful for that. The reason I wouldn’t recommend anyone to get started is not because of features PHP 7 is lacking, but it is the social stigma. Want to maximize your chances at a great career? Pick something else. This is not to say that you can’t be succesful with PHP 7, it’s just that the stigma or “negative pressure” as someone called in on hackernews will have an effect. If I were just interested in paying my bills and having a job, this might not affect me as much. I have greater ambitions and want to maximize my chances in getting there. I can live with the occasional stigma, but it’s a liability.

Thanks for all the great feedback though. I got a lot of private messages from people telling me they feel the same. I regret using such a clickbaity title, but this blog post has been a long time coming; a first draft was written over a year ago and it’s nice to get it off my chest.