Loathing And Skepticism: A look at the Myths of PHP

# I originally contributed this to newsmeek.com, but that website has since gone away, so here it is.

It's common knowledge in my social circle that I really don't like PHP. I don't like the syntax, I don't like the core library of functions, and I don't care for most of the third party libraries and applications that are out there.

I'm a bit of a language snob at times, but while I have favorites (Python and CoffeeScript), I don't claim any one language is better than all the rest - just that there are very popular languages that suck. A lot.

This topic has been beaten to death, repeatedly, with a double-clawed hammer. If you already agree, you can stop reading right here because nothing below will be new information to you.

If, however, you believe PHP is a good business choice for a new project, please hold on to your objections for just a few moments and read on.

Big Damn Disclaimer

I'm going to lay out my reasons for holding PHP in such low esteem, but first let me clarify for you what I am not claiming:

"PHP is a toy and can't be used to build large applications in the real world"

Of course not. It's certainly used to build complex, successful applications every day, by many brilliant folks all over the world.

"PHP is dead".

I know PHP is the lingua-franca of the web, and is still the most employable skill in web development. It's the best place to start for an entry-level programmer looking to find employment and start doing work as fast as possible.

"PHP is always a bad business decision."

When you have a simple app that can be written in a few dozen or a hundred lines that needs to run on an existing shared web host or you already know PHP, it's an excellent choice.

It's also important to consider PHP if the solution you need can be built very easily on top of Drupal, Wordpress etc.

If you already have a team that knows and loves it, and can build great things for you fairly quickly, PHP might be the best business choice. It's certainly a valid one.

Myths, Misconceptions and Poppycock

There are several claims I've heard proponents of PHP make that I believe are either false or misleading. I'm going to make a lot of comparisons to Python here, because it's what I know best, but most of the comparisons would be valid with Ruby, Scala, Node etc.

"PHP is everywhere - and hosting is cheap!"

Yes. PHP makes up over 80% of the internet, and every webhost offers shared PHP hosting for a few dollars a month. Unfortunately, those are mostly OLD versions of PHP. According to this survey by W3techs.com, 3.6% of servers hosting the 10 million most popular websites in the world ran PHP 5.5 or better as of September 17, 2014. 23% are on 5.4 and 23% are on 5.2.

48.5% are still on version 5.3, which came out the same month Michael Jackson died and the iPhone 3GS was released. The iPad didn't even exist outside of rumor until early the following year.

So... OLD versions of PHP are everywhere. If you're restricted by a client's existing server environments, or if you're developing libraries or applications for third parties and want a high adoption rate, you can't use modern PHP.

Hosting is only cheap if you use economy-priced shared webhosting, which often sports a version of PHP that's getting long in the tooth. If you're hosting on a virtual host or cloud service, or on your own hardware, you can run whatever language and version you'd like and hosting isn't cheaper one way or another.

# "Everywhere" and "Cheap" are not solid business reasons to pick PHP.

"PHP gets you first to market."

If your programmers only know PHP, and they're great at building applications with it, that may be true. If a large part of your problem is solved by existing software written in PHP, it's likely dead on.

If you haven't hired your team yet, your problem isn't largely solved by existing software and you have the opportunity to hire for your platform of choice, you can build an application and get to market even faster with Ruby On Rails or in Python with Django.

Even if your developers are established users of PHP (and unless they have many years of painfully earned expertise), the productivity gains may be high enough to justify a platform change anyway, assuming you get an expert or two on board to lead the way.

If your application will be large or complex, the learning curves of many other languages are shallow enough, and the efficiency and readability high enough, that taking some time to learn another platform first can result in faster development and much more maintainable code - leading to faster turnaround on bug fixes and code refactoring later. New features and maintenance will be quicker and easier. Your next project will come together surprisingly fast.

# Rapid development - that is, "first to market" - is better accomplished elsewhere.

This opinion seems subjectively biased but I'll talk about why PHP development crawls in comparison to its competitors soon.

"PHP has so many libraries to build on!"

As of this writing, PEAR (PHP Extension And Application Repository) has 595 packages and its sister site, PECL (PHP Extension Community Library) has 327. Packagist, the repository for Composer, a rather new - and pleasant - package manager for PHP, has a more respectable 33,893.

Compare that to PyPi's (the Python Package Index) 48,874 packages, RubyGems' 88,633 packages, and NPM's (the Node Package Manager) 94,739 packages and you can see that even allowing for huge variance in quality or usefulness, the alternatives are all on an even footing or far ahead of PHP.

# The important bit of information to take away is that if you want prewritten libraries that let you accomplish all sorts of great things without writing all the code yourself, you are most definitely not restricted to PHP.

"Some of the most successful web software projects are written in PHP"

Yes, Wordpress and Drupal and loads more ready-made web software solutions are written in PHP. When a lot of brilliant people come together to build something, they can build something beautiful despite the shortcomings of their tools.

# The fact that those projects are successful *because* of PHP is a myth.

I believe it took longer in PHP than it would have if they built projects like Wordpress in something else. Too bad we'll never know for sure.

The Allegations

I believe that PHP is, in almost all cases, the least efficient tool available to a web developer.

Most of my comparisons will refer to Python or CoffeeScript, because I favor them, but I don't claim that either is the best - Ruby, Scala, Clojure and many others are equally superior, for several reasons:

Weak Syntax

PHP's syntax isn't necessarily bad, it's just inadequate. There have been all sorts of developments in programming language design over the past decade, and few of them have been adopted by PHP - or, if they have, they're in versions that are too new to consider usable "everywhere".

This leaves PHP less expressive than other programming languages. It takes more lines of code to implement features, and isn't as easy to read or maintain.

Some Data: Programming Langauges Ranked By Expressiveness

Programming Languages Ranked By Expressiveness - Graph

Judging by that graph, it looks like we should all be using Clojure or eC to write our applications, but there are a lot of factors involved and expressiveness isn't the only thing that you should consider when choosing a language.

It's obvious though that PHP, according to the data, is less expressive than a lot of competing languages: Coffee, Python, Ruby, Go, Scala, Groovy and Clojure all take less lines to implement features than languages like C++, JavaScript, PHP and ActionScript.

I also found a blog post by Jeff Atwood that talks about one of my favorite chapters from Code Complete; it discusses relative language expressiveness.

The chart in the book doesn't include PHP, and neither does Jeff Atwood's article, but it's interesting to read and think about, and you can infer some things from the syntactic similarity that a few of the featured languages have to PHP.

# This has been getting better in newer versions of php - for example, the last few releases introduced Array Literals, Array Comprehensions and Generators - so if you are free to use the latest and greatest, this won't be as much of a problem for you.

Erratic Core Library

There are thousands of functions in the global namespace, including bindings for specific software packages or services that should come in third party libraries.

The core library fails disastrously to follow any conventions whatsoever. This is covered in detail in PHP: A Fractal of Bad Design, but here are some highlights:

  • "to" versus 2: bin2hex, deg2rad, strtotime, strtolower
  • argument order: array_filter($input, $callback) vs array_map($callback, $input)
  • half the array functions start with array_ and half do not

A lack of naming conventions, and such a polluted global namespace, waste time and cause undue frustration.

Really Weird Behaviour

Also explored in detail in PHP: A Fractal of Bad Design, PHP has some oddities that make me cringe.

Some short and sweet examples from that article:

  • "foo" == TRUE and "foo" == 0 but TRUE != 0
  • NULL < -1 and yet, somehow, NULL == 0

There are droves more examples that make me laugh and cry simultaneously when I read through them.

Third-Party Libraries

I've found glaring holes in the third-party libraries available for PHP whenever I've had to use it. These holes are rapidly filling up, but I always found the offerings couldn't live up to their counterparts in other languages.

Doctrine, for example - the most-used ORM in the PHP world - can't hold a candle to Python's SQLAlchemy for power and flexibility. Doctrine has probably grown up since I last used it, but SQLAlchemy has kept on growing as well. Doctrine is a nightmare to learn when compared to Ruby on Rails' built-in ORM.

I find frameworks like Python's Flask and Django a lot easier to learn and use, and faster to develop with, than some of PHP's comparable offerings (I tried Silex and Symphony). I've talked to a lot of people who have moved away from these frameworks in favor of Rails or Django, and they're happier for it. I haven't yet talked to someone who went the other way and enjoyed the experience. I have however heard that Laravel is somewhat pleasant to work with, in the PHP world.

When I looked for libraries to parse GIS data from Shapefiles last year, there were a few offerings for PHP, but they were buggy, hard to use and incomplete. Python and JavaScript had fantastic libraries for this, and Java had the worst. This is an edge case, and a quick Google search shows more options for this now, but it highlights my experience at the time.

I've seldom looked for a library for something in Python and failed to find something that fit my needs. I haven't encountered many packages that disappointed me because they were incomplete.


PHP can certainly be used to build real software, but I believe it's an uphill battle and that anyone who can build great software with PHP can build better software, faster, in something else.


Jeff Szusz

I'm a professional web developer, a novice videography nerd, and I love a good book or games with friends. I'm @jeffszusz on twitter!