Why PHP persists

David Stark / Zarkonnen
2013-10-08 06:00

So a while ago I was discussing with Jasmine why PHP, despite being an awful language, is so popular. In short, I think it's because it's easy to get into - and this is a quality often overlooked with other projects.

Let's say you have some basic knowledge of HTML, and have written a website. You now want to add some dynamic stuff to the site - maybe a database of news articles, or a commenting system, or something else that requires the site to execute some code.

Now you could do this with, for example, Django. I like Django as a framework - it comes with a lot of useful things built in, and Bumble, which this site runs on, is built on Django.

But setting up a Django instance is far from trivial. Here's a partial list of things you may need to learn about:

  • Python
  • bash
  • Apache configuration including mod_wsgi
  • Environment variables and PYTHONPATH
  • File permissions
  • SSH
  • URL routing, MVC, and Django's particular take on them
  • MySQL/Postgres/whatever

In addition, your web host may simply not support Django, or indeed anything but HTML and PHP and some Microsoft nonsense.

On the other hand, if you want to start adding some code to your website using PHP, this can be as simple as changing a file's extension from .html to .php, putting in a <? and a ?>, and copy-pasting some code into there, or even just a simple print statement.

Of course, getting from there to a site that's not a giant rickety security hole is a whole other matter, as PHP still pretty much actively encourages you to leave your site open to SQL and JS injection, not to mention XSS and other advanced attacks. But at least you got somewhere!

So you don't really need additional skills to get started in PHP. And not only is it simple to get into, it's so ubiquitous that you don't have to do a lot of setup work. Sure, you're going to have to learn a bit about SQL, but again, many hosts come with a MySQL DB more or less configured to work with minimum effort. For example, I wrote one of the much earlier incarnations of this site in PHP. I didn't understand about the WHERE clause, so my way of getting a particular row was to invoke SELECT * FROM table; and then loop through the IDs in PHP until I found the right one. Horrific? Yes. But I was in my early teens and didn't know any better. And it got the job done just fine.

In conclusion, if you want PHP to go away (and I think it really should), the solution isn't to write a really elegant web framework that does everything so much better. The solution is to write something that's as easy or easier to get into as PHP. You might say that everyone ought to learn about basic shell commands and whatnot before they write their first dynamic site, but that's not how it works. If you don't make the learning curve absolutely smooth, people who are just entering web programming on their own will continue to go for PHP.