I’ve been in the planning stages of a new product for Virtualmin users (and eventually for anyone who has a web server), which would predominantly run on on our servers. It would be our first application that allows us to choose the implementation language (our current codebase is over nine years old and includes hundreds of thousands of lines of Perl…we won’t be changing languages for our installable products, though we do look forward to Perl 6).
This got me to thinking about language popularity. PHP is, by far, the most popular language for the web. It’s also the worst among the popular choices. At least it’s the worst by every metric I consider important…except one: Availability.
PHP syntax is horrible. The vast majority of PHP code in the wild is horrible. The PHP standard library is inconsistent from top to bottom. It encourages bad practices, and dangerous behavior is the default for many PHP functions. Only in the past few years has PHP acquired the ability to safely and sanely use databases. The database problem is the cause of a huge percentage of the horrible PHP code in the wild…and folks are still writing code using the ugly way to access databases, despite better ways existing, because it’s all they’ve ever seen. PHP code, in general, is hard to maintain, hard to read, and often poorly documented (again, a lot of the documentation covers historic techniques that are simply dangerous). The object system is bolted on. It has no functional programming constructs to speak of.
So, why the heck is it so pervasive? Why on earth would smart people choose to use a language that is less effective for almost every non-trivial task in web development? And, I should be clear, smart people do choose to use it, and some fantastic applications have been written in it. This isn’t a situation where a bunch of idiots are using it because they don’t know better. Some of the coolest web applications are written in PHP, by some of the coolest developers working in the field.
The answer, and an answer that the Ruby On Rails folks, Pylons folks, Django folks, Perl Catalyst folks, etc. should all pay really close attention to (assuming they want their apps to be widely used), is that PHP is pervasive because it is pervasive. Tautology, I know, but what I’m trying to get at is that people code in PHP because they know it will work wherever they go or whoever they hand it off to. They know every web developer will be familiar with it, and will have access to a webserver that can run it. They know it will run on the cheapest DreamHost account, the midrange TextDrive account, or the most expensive RackSpace managed server, without modification and without jumping through too many hoops. They also know that if they have to hire someone to maintain it, or round up a community of users to help add features, there are no shortage of knowledgeable developers (it’s hard to find the good ones, as in any language, but some things don’t require good developers). Further, it’ll be reasonably fast, if they don’t do anything stupid or pathological with databases or files.
In short, if you want your installable application to be used, probably the single most useful thing you can do is write it in PHP. You also need to make it do something good, of course, and without huge glaring bugs. I’m guessing, but based on UI studies that show that for every field you add to a form, the completion rate drops by a huge amount (an order of magnitude in some extreme cases), I believe that an installable PHP application will initially get ten times the users of a Ruby On Rails application that does the same thing. I don’t have numbers to back up this bold assertion, of course, but I’m pretty sure that’s the way it will play out, unless and until Ruby On Rails is as pervasively available as PHP (which is unlikely to ever happen).
I don’t like this fact. I’m obviously not a fan of PHP as a language. I can’t think of a commonly used web development language that I would choose PHP over from a purely technical standpoint, except Java or C# (and even those have certain areas where they are particularly strong and well-suited for the task). But if I were building a small application (by small, I mean anything under 50,000 lines of code) that I wanted thousands of users to install, I would probably write it in PHP.
Of course, I’m not building an installable application this time…so I’ll be picking among the languages I like (Perl, Haskell, Python, Erlang). But my moments of blinding insight are few and far between, so I thought I’d share this one with the 12 people that visit my blog.

Adam Doupr | 09-May-07 at 6:06 pm | Permalink
Your post is a bit misleading. You seem to be talking about using PHP/ROR to develop an application. I think you are refering to developing something like Wordpress; i.e. something that you expect users to download and run on their own web servers.
However, I believe that the majority of “applications” that people are developing using ROR or PHP are meant for people to access on the web; not to be distributed for others to run on their web server. When you consider this context, as long as you can find one hosting company to run your app on, you’re golden.
Anyway, interesting post, and I think you’re right, and to paraphrase, being popular is the way to be popular.
David Avraamides | 09-May-07 at 6:26 pm | Permalink
Make that 13…
You make a good point, but you can also use a similar line of reasoning to make the opposite argument: that the ubiquity and relative standardization of HTML/HTTP/Javascript/CSS makes the language behind the website irrelevant.
If your product is an app that needs to be installed, supported and evolved, then your point is spot on. But if your product *is* your website – not the bits behind it – then you should pick a language that suits you and the problem. In that case, PHP would probably be near the bottom of your list of choices (as well as mine).
Remember, VB was one of the most popular programming languages of all time, but I don’t think that in itself is a good reason to use it.
joe | 09-May-07 at 6:35 pm | Permalink
Hey Adam,
I agree with you, regarding hosted apps to some degree (I even mentioned that PHP wasn’t under consideration for the hosted app I’m planning to build). But, finding a host that supports your application still doesn’t address: Finding developers that understand your platform, moving to other hosts, etc. And I guess I failed to make it clear why I think PHP is more popular: To build a Ruby On Rails application you have to pile up a bunch of tools before you can even start building an application on top of it. With PHP, you type vi myapp.php and start programming. Then you copy it to any old web server.
joe | 09-May-07 at 6:45 pm | Permalink
Hey David,
You’re absolutely right about the coming irrelevancy of back-end languages for many classes of applications. Some of the most advanced and interesting Web 2.0 apps (Zenter, Weebly, Gmail, come to mind) are big JavaScript applications that happen to use some random backend language to store/retrieve stuff on the server. It’s not really true in our applications, as we’re doing system administration…quite heavy-weight stuff on the back-end, while the front-end is often very simple (though getting more interesting in our new AJAX version).
I think the VB comparison is apt, though I think it tells me the exact opposite of what it seems to tell you. Visual Basic may very well have been the best platform for a large set of Windows desktop application programming tasks, despite its failings as a programming language…I’ve never used it, and it would never cross my mind to use it, but if it was the path of least resistance to getting an application running on the widest variety of your target audience’s systems, it was probably wise to choose it as a platform, despite its obvious shortcomings.
Again, I think we can all agree that if your application is hosted, and you have a choice of language, you should pick the best one for the job (and PHP is probably not it).
trashmaster5000 | 10-May-07 at 12:48 am | Permalink
hi
a lot of php code is unreadable because of the writer, not because of the language.
if the programmer fails to abstract his program into a series of functions which abstract lower level concepts building an application which can be understood and extended easily, do not blame the language for that.
what’s that old saying, you can write fortran in any language.
joe | 10-May-07 at 1:21 am | Permalink
Howdy trash,
One can certainly write reasonably good code in PHP, though it is not the norm. And, as I mentioned, some truly great developers are working in PHP and producing really great software. But that doesn’t change the fact that PHP has an ugly object system, no functional constructs, and an inconsistent standard library. Those aren’t things that can be solved by “…a series of functions which abstract lower level concepts building an application…” They are serious shortcomings of the language. We can certainly work around them, just like I daily work around the ugliness in the way Perl handles function arguments.
I’m not saying PHP is alone in having such shortcomings. Just last week, I posted complaints about Perl and its bolted on object system. Many languages get objects wrong. Even Python, which a lot of people consider very pretty, has some object ugliness with the whole “self” thing. Ruby gets objects beautifully right, but falls down in other areas. But PHP is unique in having problems in almost every area. It’s got a standard library that is inconsistent in almost every way: names, calling conventions, return value conventions, etc. Database and various other operations that are unsafe and inconsistent, by default (as I mentioned, database access was fixed a few years ago, but people still call the databases directly and use the unsafe and database specific conventions that were available in PHP3). It’s just an ugly language.
But, it’s the most widely used. And that has a helluva a lot of value. Did you miss the part where I ended up recommending it for installable applications, despite all of the bad-mouthing about it? No reason to pretend it’s a lovely language, even if I agree that it’s the best choice for a lot of types of applications.
Cruise | 10-May-07 at 5:46 am | Permalink
“…and folks are still writing code using the ugly way to access databases, despite better ways existing, because it’s all they’ve ever seen.”
There are better ways in PHP, or in other languages? If there are better ways in PHP than the standard way you see in every PHP/MySQL manual I’d love to see some example code.
I agree with the other replies that said bad programming is due to bad programmers, not (in this case at least) a bad language. PHP gives you the ability to abstract away a lot of what is normally considered bad by way of functions and an object system. The majority of programmers not using those features isn’t the fault of the language itself.
PHP’s low barrier to entry means that most of the coders working in it are copying out of the manual. The rest of us who know better should be giving them good examples to follow.
joe | 10-May-07 at 9:47 am | Permalink
Hey Cruise,
I was referring to better ways within PHP. Most folks are still hitting MySQL with MySQL-specific functions and then later on adding PostgreSQL, or whatever, support in an ad hoc fashion (if they support other databases at all). MDB2 and PDO are options to avoid some of that (not comparable to Perl’s fantastic DBI, but still a big step up from the blindingly stupid mysql functions in stock PHP). In short, the default database stuff, that is most widely documented and discussed, is just as bolted-on and ugly as the PHP object system…moreso, actually, because it’s downright dangerous if used without extreme caution (encouraging SQL injection is pretty much the default behavior, for example).
I’m not a PHP hacker, by any stretch…So, I’m not the guy to give good examples. I wrote my first PHP application a few months ago for translating OpenACS data over to Joomla, and have written a few small modules and patches to various Joomla components…very limited experience. And I used the blindingly stupid way of accessing the database, because that’s what Joomla does. I copied bad code, just as you’ve suggested is the source of much bad code. So, I absolutely agree that the bad code is due to lots of copying of bad code.
I’m just here to complain, not provide solutions.
But, PHP is still an ugly language. One that can be used with great results, when wielded by a smart developer, but that doesn’t mean it isn’t ugly. I would encourage folks to give a try to a nice looking language, just to get some perspective. Ruby and Python qualify (Perl can be beautiful, but it suffers from some of the same problems as PHP, in that much of the existing code is horrible…and it has a few clangers of its own, like ugly objects and downright stinky argument passing syntax, both to be fixed in Perl 6).
c0ldfusi0n | 10-May-07 at 11:26 am | Permalink
Ironically, your blog is built with PHP. If you hate it so much, why didn’t you just coded your own using your oh-so-adorable Perl? Answer’s simple, it’s easy and it’s there. And any idiot who criticizes PHP on a daily basis such as you contribute to the hype by saying it’s a bad language without any constructive proofs whatsoever. When you’ll have coded your own website, whine again. Meanwhile, have a bite of the collective biscuit.
Victor Saldaña D. | 10-May-07 at 11:41 am | Permalink
“PHP code, in general, is hard to maintain, hard to read, and often poorly documented…” bad bad PHP… or bad bad developers?
Poor arguments.
joe | 10-May-07 at 11:43 am | Permalink
Hey c0ld,
Touched a nerve, eh?
I suspect you’ve missed the points I was trying to make. I’ve been quite specific about what I believe is ugly in PHP (bolted-on objects, flimsy or non-existent database abstraction and unsafe by default constructs in most code, inconsistent standard library and syntax, and a vast array of bad examples of code in the wild that newbies copy verbatim, thereby passing on the meme of bad software design in PHP). And despite all of those problems, I’m still recommending PHP for the vast majority of installable applications.
I’ve also made clear that some of the best web applications in recent years are written in PHP, and I’m obviously fond of WordPress.
I’m sorry to have offended. I guess I come from a programming culture that has thicker skin. I suspect if I were to criticize perl in the same way (and it could have been criticized for exactly the same reasons when it was the most popular web development language several years ago, but I wasn’t savvy enough of a developer to be aware of it), perl developers would respond, “Yep, that’s interesting, isn’t it? Well, I guess I’ll get back to work now.”
Actually, now that I think about it, I pretty much have criticized perl for some of the same things in this post and others. It just didn’t raise a ruckus the way this post has.
So, take it easy. I’ve just said your favorite language has a killer feature, and is the one people generally ought to be developing in. And I also said, effectively, what you’ve said about PHP: “it’s easy and it’s there”. And, I don’t criticize PHP on a daily basis. I’m a perl guy…I’ve got work to do.
joe | 10-May-07 at 11:54 am | Permalink
Hey Victor,
“bad bad PHP… or bad bad developers?”
A little of both.
Tufty | 10-May-07 at 1:00 pm | Permalink
PHP does have a lot to answer for. I use it for my work, where I’ve seen EXACTLY the sort of things you talk about here (it’s something I’m gradually pushing to change, but 5+ years of entrenched code that works, despite being ugly, takes some fixing).
Yet, I also choose to use it at home, and for my personal sites. Part of that reason is the fact that it’s everywhere – it was no problem finding hosting for a sensible price (I got 4 years for £110). The other reason is that, correctly used, PHP _can_ be as beautiful as the other languages. To emphasise that point I use CakePHP, a RoR-like MVC framework, and I find myself more than satisfied with the results.
Don’t look at the majority of existing PHP applications to judge the quality of code. WordPress has awful code behind the scenes, for example – which is probably why it’s only in recent releases that they’ve reduced the number of exploits possible.
In summary, I agree with you pretty much completely!
Nick Halstead | 10-May-07 at 4:30 pm | Permalink
I am afraid you have zero clue about PHP. You talk about it as though we are still using PHP 3, Bad PHP code is written by bad PHP coders, bad Java is written by bad Java coders.
You state that ‘PHP is hard to maintain’? But give no justification for this statement. You are obviously completely unaware of the abilities of PHP 5. Which now has all the class inheritance, abstraction / interfaces / reflection that any other modern (ruby included) has.
I have in the last two years worked on several massive PHP projects with thousands of classes and hundreds of thousands of files and code maintenance has been no different than any other programming language.
The fact that so many of the large players IBM/Oracle/BEA all now getting in bed with PHP it shows that they all want to be apart of the future of PHP.
I suggest you get your facts straight before you post such rubbish in the future.
joe | 10-May-07 at 5:25 pm | Permalink
Hey Nick,
Thanks for your comments. I’ve answered all of your points in previous comments, so I won’t re-iterate in detail here. All of my assertions are about PHP5. I’ve never used anything else.
Some of my statements are about common practice, and I believe I’ve made that clear. For example, my problem with database usage in PHP is pretty much entirely because people are still using the stupid PHP 3 functions to access databases. I specifically mentioned the solutions to that problem above, but the existence of a good way doesn’t alter the fact that the vast majority of code is written the wrong way even today.
But, there are also significant issues with the language:
- PHP objects are in no way comparable to the everything-is-an-object design of Ruby. (To be fair, neither are Perl or Python objects.)
- PHP has an inconsistent standard library.
- PHP has inconsistent and wrong-headed syntax. Example: ==, ===, false vs. null. This, to me, is indicative of ad hoc, and not very carefully considered, design.
Finally, I’m sure your code is beautiful. No need to imagine I’m speaking about you specifically. You could, in fact, be one of those “coolest developers working in the field”. I wouldn’t think someone in that category would be so sensitive, but it could happen, I guess.
Oh, yeah, I’m not sure why you would want to compare PHP to Java…Java is even worse, but for very different reasons. And the involvement of IBM, Oracle and BEA is for the same reason they got involved in Java: Popularity. The more users there are, the more money there is to be made on tools and consultants for the language. Very simple math. It’s the same reason I say that we mostly ought to be writing our small installable web applications in PHP.
Nick Halstead | 11-May-07 at 1:42 am | Permalink
I do agree that yes there are lots of projects and still developers out there using VERY bad practices when using PHP. And that database access is certainly one of them, with PHP 5.1 and the inclusion of PDO things have improved a lot. But I guess there are still a large % of developers that probably reading this would go, PDO.. err what?
On top of that you have things like the Zend Framework which has further DB abstraction (and on top of the PDO). In fact the Zend Framework model is one of the nicest I have worked with for a long time.
I am not familiar enough with the nitty gritty of Ruby to argue with the everything-is-an-object way of doing things. But I would in PHP defence say that with its magic keywords __call, __set,__get allow you to make a class act in any way you desire.
Yes PHP does have a lot of inconsistencies, especially in some of the parameter orderings for various string handlers (shudder). But these things can be forgiven, and I have come across similar problems in every other language I have programmed in.
I certainly wouldnt compare Java to anything as I hate Java, I was just making the point that bad coders = bad code. Which you have already agreed with.
So to summarise, PHP is in a difficult situation of too much success for bad reasons, and it is going to be difficult to extract itself from this position which is why adoption for PHP 5 is not higher (current around 17%) and we may have the embarrassing position that PHP 6 could be with us before most web hosts move to 5.
joe | 11-May-07 at 2:52 am | Permalink
Hey Nick,
Exactly. You see, we actually agree on a lot more than we disagree on.
Though I do have to point out that it’s the __call, __set, and __get convention that I find ugly about PHP objects (and Perl and Python, though they use different keywords and syntax and Python gets it closer to right than PHP or Perl). It is, as I’ve said, bolted-on. It’s not the natural way to write code in the language, and it therefore is always a point of friction. If you spend a few hours with Ruby or Smalltalk, you’ll see what I mean about objects–if they are a core part of the language you don’t need keywords or extra syntax to work with objects. Everything is an object, therefore you don’t have to spend a lot of time telling the interpreter that you’re building an object! That’s why PHP objects are ugly.
Functional constructs in PHP are also close to non-existent, though I did find while researching one of my responses here that it does apparently support closures and anonymous functions. I’ve never seen them used in any PHP code I’ve seen, and I couldn’t find a good example of the syntax and usage, but it’s probably a start, anyway. We use functional constructs in our perl code quite a lot (map, in particular is really useful in the tasks we do and provides a very natural way to work with the data we deal with). Googling for functional techniques in PHP reveals very very little…so it seems to be a completely ignored paradigm. That’s a big negative in my view.
The Programming and Management Blog » 10 Reasons why PHP is still very much alive | 11-May-07 at 4:15 am | Permalink
[...] would like to thank Joe over at Obscene Art and Chris at @TheKeyboard for giving me inspiration to write this post. Tags php [...]
Nick Halstead | 11-May-07 at 10:18 am | Permalink
Hi Joe,
You gave me a topic for my latest post
I did a kind of followup with why PHP is still very much alive (in my opinion), have a read here – http://blog.assembleron.com/2007/05/11/10-reasons-why-php-is-still-very-much-alive/ am sure you will have something to say in response
Coder | 28-Jun-07 at 1:29 pm | Permalink
I am only really used to PHP but you make a good point.
tellef | 27-Jul-07 at 6:43 pm | Permalink
I dont do any programming at all in any web-language. The only thing i program are humans that do work on machines. I read joe`s blog because he is a good writer. And the way the web looks I think it is safe to say that good writers are even fewer than good programmers…php or not
The popularity issue is good, it fits with many issues i think.