6 Reasons PHP is a Mutant Toolbox

“Imagine you have a toolbox. A set of tools, looks okay, standard stuff in there. You pull out a screwdriver, you see it’s one of those weird tri-headed things, okay?… Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. There is no clear problem with the set as a whole. It still has all the tools. – Ian Baker, eev.ee

PHP is one of the most used yet most dreaded programming languages of the modern era. A Stack Overflow industry survey ranks PHP second to last on the most loved languages list and fifth on the most dreaded language list. So that’s a pretty lousy reputation across the board.

Usually, when you ask a software engineer about PHP, you’ll get one of two responses.

  1. They use it and hate it.
  2. They haven’t used it, but they’ve heard they’ll hate it.

You don’t really get any other opinions.

So why is PHP so bad?

1. PHP is Popular on the Web

“There are so many awful things involved in this abomination of a high-level programming language, it outright exceeds full-blown ridicularity. […] Its popularity is completely undeserved and I repeatedly find myself facepalming, thinking about how it is possible that this piece of junk gained even the slightest hint of acceptance.-  Why Does PHP Suck

A lot of us hate PHP for the same reason that we hate JavaScript – because it’s the most popular. After all, 80 percent of the web runs on PHP.

If you look at the top languages on the web right now, you see JavaScript at number one and Typescript at number three, but that’s really just a version of JavaScript. Python is at three, but PHP is still right in there at number four.

Massively popular Content Management Systems (CMS) built on PHP like WordPress, Drupal, Joomla, Magento, ExpressionEngine have been around for decades. PHP is everywhere because it hosts these easy-to-use sites.

There are also so many frameworks for PHP, including Laravel, CodeIgniter, Symfony, Cake, Yii, Zend, PHPixie, and tons more.

PHP’s ease of use has allowed it to become the number one de facto language used on the internet.  So is the bad reputation deserved even beyond the fact that it’s just the most popular? 

2. PHP is Unpredictable

“I really don’t like programming. I built this tool to program less so that I could simply reuse code. I don’t know how to stop it. There was never any intention to write a programming language. I don’t know how to write a programming language at all. I just kept adding the next logical step.” – Rasmus Lerdorf, the creator of PHP

That is kind of the whole thing about PHP. There was never a plan, and so PHP is unpredictable.

For example, there’s a function called mysql_escape_string, which is defined as, “It escapes a string for use in a mysql query.” But there is also a function called mysql_real_escape_string, which is defined as “Escapes special characters in a string for use in a SQL statement.”

You have to dig into the documentation to find out the real difference between the two. It’s incomprehensible.

They have 13 different functions just to sort an array. And speaking of arrays:

Arrays are yet another weird quirk that you must endure in PHP. Instead of being just numerically indexed, arrays are a terrible amalgamation of pretty much everything. They can be treated as an array, a list, a hash table, a dictionary, a collection, a stack, a queue, and probably more. – Ian Baker, PHP: a fractal of bad design

3. Inconsistent Naming Conventions

PHP has inconsistent naming conventions. There is strpos for the position of a string, but str_replace with an underscore to replace text in a string. Those begin with STR, but other string functions do not: trim has no STR, and substr has the STR at the end. The naming conventions for string functions are all over the place.

You’ve got urlencode without an underscore versus utf8_encode with an underscore. You’ve got html entities versus html_entity_decode with and without underscores. You’ve got disagreements in their verb-noun or noun-verb naming, array_merge versus get_class.

What else do we have?

4. Case-Sensitivity

Variables, constants, and array keys are case-sensitive. But keywords, functions, and methods are NOT case-sensitive.

Order of arguments: strpos has a haystack and a needle. But array_search has a needle and a haystack. So the order of their arguments is inconsistent. They’re just arbitrary.

That’s just a small example of some of the problems with PHP.  However, most of these issues have been around since the early days of PHP.  But PHP, like JavaScript, has come a long way since version five.

5. The Legacy Code from 1995 is Still There

PHP started as just a basic templating tool that Rasmus Lerdorf used to manage his own personal website. He never intended for it to be a programming language, but he posted it to a Usenet group in 1995 and said, “Hey, look what I made.” In that first post, he called it PHP/FI.

Other people started hacking on it and released PHP/FI2 in 97. Then, in 98, they released PHP 3, which was the first time it actually resembled a programming language. Then PHP 4 came in 2000.

PHP 5 came in 2004, and here’s where development hit a roadblock. PHP 5 hung around for ten years before the next version was released. They went through six versions of PHP 5, and they added all kinds of nice stuff to it during that time. But it was a ten-year cycle.

During that time, they were working on PHP 6, but there were all kinds of development problems. PHP 6 went into development hell, and it wouldn’t see the light of day due to issues with the way they were implementing unicode support. They were also trying to work on the i18n and the l10n issues they had for foreign language support. They basically spent several years going in absolutely the wrong directions before they finally scrapped PHP 6 altogether.

They finally released PHP 7 in 2015, eleven years after PHP 5 was released. First off, they made a lot of improvements in PHP 7. Then, finally, it started to resemble something real, something usable. They added things like the null coalescing operators, scalar type declarations, return type declarations, the spaceship operator, constant arrays, anonymous classes, unserialize, closures, all kinds of things. And they ended up turning it into a darn fine language.

PHP 8 was released in November 2020, and it’s got a new just-in-time compiler. They’ve made lots of improvements to the type system to make the weird typing things that PHP used to do a thing of the past. In addition, there’s a nullsafe operator. So there are lots of great things to explore in the newest versions of PHP.

But all that legacy PHP stuff is still there.

6. A Language Full of Problems

“Imagine you have a toolbox. A set of tools, looks okay, standard stuff in there. You pull out a screwdriver, you see it’s one of those weird tri-headed things, okay?… Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. There is no clear problem with the set as a whole. It still has all the tools.

The carpenters show you the houses that they’ve built with it, where every room is just a pentagon and the roof is on upside down and you knock on the front door and it just collapses inwards. And they all yell at you for breaking their door.

Well, that’s, what’s wrong with PHP.” – Ian Baker, eev.ee

Since PHP 8 has not been rewritten completely, most of the old problems are still there. So those functions still have to be used. And because of the incomprehensible way they’re put together and designed, you pretty much have to have the PHP documentation open at all times so that you can look up how to use all of it. It’s illogical.

Even though you’re using this nice new syntactic sugar that they’ve put on top of it, the base remains broken.

And that’s why developers like me hate using PHP.

More Posts by Dan Horne: