
PHP is a strange and (let’s get it over with) ugly, little language. It’s not exceptionally fast. It’s not beautiful syntactically. It’s not formulated around a clear opinion. And it’s still what I write a lot of software in. The obvious question is: why?
Well, It’s EVERYWHERE…
There are a lot of reasons to know and love PHP, probably the most potent and valid of which is this: it’s used and runs EVERYWHERE the web does. Your cheap little $3 per month hosting account may let you run a web application in Python or Ruby if you shop carefully. But it’ll definitely run PHP. This means that you can count on it wherever you are.
And because it runs everywhere, and is easy to get started with, a lot of very popular software is written in PHP. WordPress is the example that’s both largest and most familiar to us here at Press Up, but also Joomla, Drupal, Magento, ExpressionEngine, vBulletin (yep, that’s still around), MediaWiki, and more are all running PHP on the server.
And there are more PHP frameworks than you can shake a stick at as well: Symfony, Zend, Laravel, Aura, CakePHP, Yii, and even the venerable CodeIgnitor. Surely you can make a list of web frameworks of some length for almost any other language. And for the commonly used web languages like Python, Ruby, or Node/Javascript you may even be able to amass a numerically competitive list. But the sheer volume of sites running PHP is crazy.
WordPress proudly boasts that it powers more than 20% of the internet. You don’t need to even trust that fact to realize that a lot of the internet must be using PHP if that fact is even conceivably true.
and it has some good qualities
PHP does HTML rendering and programming easier than any other language.
PHP does HTML rendering and programming easier than almost any other language. Just change your file.html
to file.php
, add a bit of dynamism inside some <?php
and ?>
tags, and count on Apache doing the rest for you. It’s so simple that almost anyone can get started without a need for much more of an understanding of programming than this. Because PHP is so friendly to cut your teeth with, a lot of bad code is written in it, and it’s gained a bit of a negative reputation.
Once you get people to realize that most bad PHP is written by bad programmers, most of the fear and hatred of PHP you encounter in the world comes from one other essential problem: PHP has never had a grand designer with a visionary idea about why it was the perfect language for your web server. Instead, its the result of wide collaboration through an open and arguably toxic process which serve as a crucible through which any good idea — and a few bad ones — must pass.
And bad ideas can make it through that crucible. The most popular example is that PHP 5.3 — separately widely regarded as the first modern version of PHP — introduced the
goto
statement, which is generally either scoffed at or thought an easy source for errors. Similarly bad thing in PHP that have resulted from the process through which the language has grown: object-orientation was first implemented as a flawed and limited concept, the standard library is full of inconsistent names and parameter ordering, and (in an example that recently got a fair amount of attention) the ::
token is called by the interpreter by the inscrutable to English speakers: T_PAAMAYIM_NEKDOTAYIM
.
But those thing said, PHP is evolving in interesting ways. It’s growing toward being a pretty fully-featured Java-like (for better or worse) object-oriented language. And much like Java, it’s gaining easy abstractions for functional programming — arguably the current hotness. It’s also growing a pretty awesome set of tools — PHP loves Composer, and for good reason — and a commendable effort to make all of these large open source projects in PHP work a little bit better together. Oh, and we shouldn’t forget the current hotness: the potential speed gains from the HHVM coming out of Facebook.
It’s about what’s right for you
I’ve enumerated some of the things that are bad about PHP, and I feel some of them regularly. Needle and haystack inconsistency in search functions bites me at least once a month when I’m quickly doing something without autocomplete.
For a true and complete greenfield project, with no need to interoperate with any other system, or need to run in any arbitrary environment, with no existing expertise on the team, I’d think pretty deeply before I recommended PHP. But that was, as you read, a lot of caveats, each of which is a great reason for even a fresh greenfield project to be written in PHP.
Any modern web language can help you make good websites and apps. And every one of them has features that aren’t ideal. PHP, like any of them, requires you to truly understand its tradeoffs for you in your project to determine whether or not it makes sense for you. But for me, personally, I continue to find that it’s possible to be — as Keith Adams put it in a great talk — “shockingly productive in PHP.”
Image Credits: timbrell
Great article.
I think the ship is turning slowly. No more PHP bashing. We all were there few years ago. It was bad, like really bad, but things evolve and get better. PHP have matured hugely in past 2-3 years. All those “haters” should give PHP second (or even maybe third chance) it will be totally worth it.
Pingback: Why PHP? | Simon Hall
Pingback: What the Heck is the HHVM? | Press Up