Some thoughts about PHP

I have been using PHP1 as my primary language for five months now so I feel somewhat qualified to speak about it. My overall conclusion is that PHP is weak sauce. It is easy to get started with PHP but it’s usefulness decreases as the complexity of the application increases. This is primarily because keeping PHP code maintainable requires unnatural levels of discipline. Choosing PHP for a greenfield project is a technical risk that is unnecessary in today’s rich web application ecosystem. Of course, most projects aren’t greenfield so there are plenty reasons to have PHP around.

I find PHP to be a deeply frustrating environment in which to work. It seems to have occurred, as opposed to designed or even evolved, without much of an overarching vision. In “The Mythical Man-Month” Fredrick Brooks claims that “conceptual integrity is the most important consideration in system design”. Unfortunately, PHP has very weak conceptual integrity. It seems mostly to be a collection of decisions that seemed expedient at the time with little thought about how that would impact the over all system.

I remember hearing a few years ago about PHP is syntax to appear more Java like. That was back when it looked like there was going to be a real Java hegemony in business programming. At the time I thought it was a slightly odd but defensible idea. Today I see that decision as an indicator of weak conceptually integrity. I think any system willing to give up its character so completely must lack, almost by definition, the conceptual integrity needed to be great.

I covered several concrete issues with PHP in Early impressions of PHP. All of those issues still stand but my biggest problem with PHP, after working with it for a while, is that is seems designed to actively discourage meta-programming. This means I find myself writing annoying amounts of boiler plate code2. I strongly believe that the future of programming is language-oriented. This make PHP hard for me because even rudimentary language oriented techniques are simply not feasible in PHP.

A Somewhat more minor annoyance is the lack of closures and blocks. I first learned blocks and closures about two years ago and now find programming without them mildly painful. I think that Mark Jason Dominus got it right when he said

in another thirty years people will laugh at anyone who tries to invent a language without closures, just as they’ll laugh now at anyone who tries to invent a language without recursion.

There are just so many common classes of problem that are simply and cleanly solved by closures that not having them seems like a crime. I hope it does not take thirty years, though.

It would not be fair to leave this post without a discussion of the good things about PHP. PHP excels at lowering the barrier to entry. There is no other system I am aware of that even come close the ease of getting start with PHP. The weakness of PHP’s conceptual integrity does not seem to noticeably impact productivity in the context of small systems. The idea that you can have a web application by creating one text file and copying it to the web server is radically powerful.

And then there is Smarty. Smarty is a really nice external DSL for generating web pages, i.e. a template engine. The core of Smarty is well thought out and has very nice extension mechanisms. I is a joy to work with. If you are doing PHP work I can strongly recommend Smarty.


  1. As always, I need to point out that I am speaking primarily about PHP 4. I suspect that PHP 5 suffers from many of these issues but I have spent very little time in PHP 5.

  2. Usually this boiler plate code gets written after I have already spent an inordinate amount of time tyring and failing to automate it. The usable area in PHP seems remarkably small. That means it is going to take a bit more running into the edges before I completely accept that they are really that close.

Comments 5

  1. Mario wrote:

    Obiously, you’re still a newbie to PHP. I’ve been using it for over 5 years, and since PHP5 i keep discovering new possibilities, new design patterns and new techniques to make PHP code maintainable and logical.

    You should invest more time in PHP5’s Object Oriented Programming, and then start learning Design Patterns. It’s the only way to score the chicks and achieve world-peace with your webapplication.

    By the way, i can recommend CakePHP.org very much!

    Posted 19 Oct 2006 at 1:35 am
  2. Dick Brodine wrote:

    Is PHP a skill that will pay your bills over an extended period of time? Or is PHP just a flash in the pan, a fad? Java, which you don’t particularly care for, takes ages to write and test. Java is all over the world. So my Java(J2EE) skills should see me to retirement.

    Where do you see yourself going with 5 months of PHP programming experience?

    Posted 19 Oct 2006 at 12:03 pm
  3. Peter Williams wrote:

    I would say that is not a “flash in the pan”. It has been around a long time already and is likely to remain active for quite sometime. As for paying the bills, finding PHP work is not hard. There are a lot of shops that use it. I doubt it would sustain me until retirement but I would guess it will still be reasonably easy to find a PHP job in 10 years.

    It is hard for me to judge what exactly will happen with PHP. There are several interesting new frameworks for PHP5. However, I think PHP’s paradigm is flawed (I think that an application server is a better approach than a page server) so I am unsure exactly how much progress can really be made.

    Posted 20 Oct 2006 at 10:45 am
  4. Dick Brodine wrote:

    Skill marketability is an important consideration if you plan to be a developer for an extended period of time. Having been a developer for most of the past 31 years, I sometimes look at my resume and find things like Inquire Database. Inquire was the hot setup back in the early ’80s. However, Inquire turned out to be just a fad. SQL came along and blew it away. That’s the point I’m trying to make about PHP. Perhaps its a viable skill. In the long run, that’s what is most important. Cobol/CICS/DB2/VSAM and a lot of Pl/i paid my bills for years. It looks to me like Java is and/or will be just as pervasive, that’s why I “place my chips” there. There’s nothing worse than pleasing a boss/company by picking up some arcane skill only to find you can’t get another job when(not if) you come out of there.

    Posted 20 Oct 2006 at 2:07 pm
  5. anonymous wrote:

    …because keeping PHP code maintainable requires unnatural levels of discipline

    This is because you have no discipline nor the desire to produce maintainable code.

    [I changed the attribution of this comment because the original attribution was obviously false.]

    Posted 07 Nov 2006 at 3:44 pm

Trackbacks & Pingbacks 2

  1. From Anne 2.0 » Blog Archive » links for 2006-10-11 on 11 Oct 2006 at 6:10 pm

    […] Peter Williams » Some thoughts about PHP “I find PHP to be a deeply frustrating environment in which to work. It seems to have occurred, as opposed to designed or even evolved, without much of an overarching vision.” (tags: php coding language-wars) […]

  2. From If not Java EE, then…? on 12 Oct 2006 at 12:32 am

    […] But honestly? In my gut, I hesitate to propose PHP because of the language itself. It doesn’t feel that much better to write PHP code than Java code — sometimes it’s worse, especially some of PHP 5’s Java-inspired syntax. Mostly, though, I think it’s the lack of closures and blocks, language features that I’ve come to expect and rely on. Peter Williams brings up the same point about PHP. I first learned blocks and closures about two years ago and now find programming without them mildly painful. I think that Mark Jason Dominus got it right when he said in another thirty years people will laugh at anyone who tries to invent a language without closures, just as they’ll laugh now at anyone who tries to invent a language without recursion. […]