The internet is filled with articles about how bad PHP is. Try a quick Google search for “PHP sucks” and you find about 83 million results. Doing the same search for other languages still gives you millions of results, but PHP really stands out in these numbers.
Although I agree that PHP probably is not the most beautiful language to work with (it’s getting better), PHP must be doing something right. Most of the really detailed rants about PHP date from the old days of the language. I often feel that the arguments being used to claim that PHP sucks, are the same issues when talking about bad practices for developers. Of course you can write bad code in PHP, like you can in any language.
I’m a fan of PHP, but for different reasons than you might guess. I am very well aware of the flaws in the language and cringe every time I do silly stuff like mixing up needle and haystack order in function arguments. The claim that PHP is bad is too easy for me though, because it’s simply not true.
Looking at the usage of server-side programming languages for websites, PHP really stands out. PHP is being used by over 80% of all websites that the we know the programming language of. This is not a small majority, this is an absolute victory when just looking at the data.
WordPress is now powering roughly 20% of the internet and consist for a really large part of PHP. I like to think that it’s because of PHP that WordPress has become so popular, but I think it works both ways.
Of course, I understand it’s not that simple and I’m not going to look at just the numbers. But it gives a good impression of how widely PHP is used. If it were that bad, surely other programming languages would be closer to PHP when it comes to market share, right?
Maybe it’s more fair to have a look at the TIOBE community index, where PHP currently sits in sixth place. PHP used to be more popular in that index, but it’s still ranked higher than Ruby, Python and other languages that are often claimed to be ‘better’ than PHP.
PHP suffers from the past
Besides the millions of search results for “PHP sucks”, there are also over 100 million search results when searching for “PHP tutorial”. I think that about 99% of these tutorials are based on old PHP versions, have flaws in the described code and generally shouldn’t be available anymore. But they are and we need to deal with it.
All these tutorials, outdated and plain bad examples are the real problem for PHP. Yes, PHP has namespaces, closures, traits and many more cool stuff that developers love. The vast majority of the content on the internet doesn’t use anything of this though.
People now getting started with PHP will likely use Google a lot. Heck, I use Google a lot still. Less experienced developers will find these outdated tutorials and will learn PHP that way. They basically learn something that should be done differently if learned today.
It’s about code, not about languages
To me, a programming language is as bad as the code people write in it. You can write pretty good code with PHP, just like you can in Ruby, Python or whatever fancy language you want to write it in. I’ll be one of the first to say that I prefer Ruby syntax and structure over PHP, but that doesn’t mean PHP is bad.
As a developer, it’s your job to write good code. If you are using PHP for a project, you can still write good code. If you decide to use Ruby, you can write good code. It’s time to leave the PHP legacy behind us and focus on how we can use PHP for our projects. PHP is here to stay, if we like it or not.
Bottom line is, as explained by this tweet by Jeff Atwood, it’s all about preference.