A long time has been passed since the first release of PHP. Over the years the language has been improved a lot, in terms of performance and features, thanks to the work of many contributors. At the same time, also its adoption among developers is grown dramatically. Looking at the latest statistics, PHP is used on the 81.7% of all websites; an outstanding result. Nonetheless, several top companies and developers have always looked at PHP as a kind of bad, silly, and for snotty kids language.
In this highly opinionated article, I’ll try to explain some of the reasons behind these judges. I’ve collected them over the time, talking with other developers and reading some articles spread on the web.
Note: Some of you might be really bothered after reading this article. I understand you, but I think that, as developers of the same community, we have to understand what people complain about our language of choice, and how we can improve the language itself. Moreover, knowing what people think are the weak points of PHP, we might prepare ourselves in explaining others which of them are just false myths caused by the misinformation.
As I said, PHP is widely used over the web as a backend language and its grown is increasing very fast. In fact, until few months ago its usage was at ~75%, a gain of the 6% in a relatively small amount of time. If you’ve been a PHP developer for a while now, you know that it’s usually hated by a lot of colleagues and it’s felt as a language that a serious company can’t employ. Sometimes I think PHP is as hated as (older versions of) Internet Explorer by web designers. After all, as Bjarne Stroustrup, who designed and implemented the C++ language, said
There are only two kinds of programming languages: those people always bitch about and those nobody uses.
Now that you should have enough context, we can delve into the discussion. So, without further ado, let’s discuss the main points PHP is blamed of.
The topic discussed in this article is so well-known that a lot talks have been given about it. One of these talks, that I had the chance to attend few months ago, was What’s wrong with PHP? by Ole Michaelis. In his talk, he asserted that the main reason behind this hate is the spaghetti code that old developers (those coming from PHP 3) or beginner developers have written over the time. He also included the version of himself at the beginning of his career and, to be honest, I have to include myself too. You know, everyone is a beginner at the start. Apart from this consideration, I strongly disagree with his analysis. In fact, the same kind of spaghetti code can be written in other “more enterprise” languages like Java. An example? I don’t have to look much far from myself. Not so much years ago, I developed a website using Java EE, because at my University people usually use it, and my JSP pages were full of spaghetti code (being Italian, I love spaghetti!).
Apart from the jokes, the point is that PHP can’t be blamed of encouraging beginners to write bad code. In every language you can find this practice because it’s usually the style beginners have. Moreover, today PHP has the same high level tools (Composer, PHPMD, PHPCS) and frameworks (PHPUnit, Twig, Symphony, Zend Framework) that you can find in other praised languages. In conclusion, my take is that this is surely one of the false myths we have to fight.
A Not-Enterprise Language
Many developers say PHP can’t be used on serious, high volume, and resource intensive websites. In my opinion, this is another false myth. PHP is reliably used by a lot of top companies like Facebook, Wikipedia, Yahoo, YouPorn (I tweeted about this) and much more, for their products. And if these companies can use PHP, your company can use it too. No other words are needed.
This is one of the most hot and frequent point I heard from PHP’s haters. Because the subject is really broad, I’ll cover just some of them, splitting the discussion in sections.
One of the most frequent complaints I hear about PHP is about its inheritance model. Developers are confused about the inheritance type exposed by PHP. Until few years ago, if anyone had asked me “What type of inheritance is allowed in PHP?” I would have firmly and rapidly answered “Single!”. Then, after the introduction of traits in PHP 5.4, I continue to answer in the same way but just…less firmly. Let’s talk clearly: PHP has single inheritance but traits allow for a sort of multiple inheritance. So, if people are right or not on this point depends on your point of view. On my side I can’t say they are totally wrong.
Functions Naming Inconsistencies
As a PHP developer you should be aware of the lot of inconsistencies the language exposes. Let’s see some examples:
- Array functions starting with array_ and not:
- Underscored vs Not underscored names:
- To vs 2:
- Arguments order:
- Object+verb vs verb+object:
I have to admit that I agree with this point. It’s not very easy to remember all these exceptions and I think this should not be necessary. Fortunately for us we have IDE that help us with functions name, but I really hope in a refactoring to achieve a more consistent naming sooner or later.
Other Design Oddities
This section lists some other PHP’s oddities, in random order, that people complain about that I’ve heard:
- PHP is the unique language where the ternary operator (
?) is left associative
- Silly error messages like the famous
- The plethora of aliases that lead to confusion:
- The PHP type comparison tables
There a lot of other stuff I could have mentioned that I’ve heard or read, but continuing the list is pointless and, honestly, I can’t remember them all. The fact is that we should be aware that PHP isn’t perfect and it has several points to improve. Nonetheless, we should also be able to point out what are false myths.
If after reading this article you feel sad about your favourite language, don’t mind. As I said in my talk few months ago
People want to perform tasks, not listen you talking about programming languages. So, use the one you feel more comfortable with and just release the next big thing.
People usually love to have an “enemy” or something to complain about. But, as we’ve seen in this article, some of the things that other developers charge to PHP are just false myths or bullshits (as Brad Frost loves to talk about). So, as far as you’re happy with PHP, as I am, continue to use it. I hope you enjoyed the article and that it gave you the chance to ponder about some PHP oddities and how you can protect your language of choice.
To conclude, in case you’re curious to read articles where people complain about PHP, here is a short list: