An Argument for PHP

Currently, over on Slashdot, there is an article on forthcoming features in PHP version 6. And, like most PHP articles, the comments section is flooded with jackasses arguing that PHP sucks as a language. I get frustrated by the entire “PHP sucks” campaign, largely because it’s like the HTML e-mail argument – mostly driven by the fact that it’s stylish to hate them – but I’m going to go further. I argue than everyone posting about how PHP is a bad language as a whole is an idiot. Every single one. Each is a foolish, arrogant, nerd sheep who can’t think for themselves. Update 5/14/08 20:39 UTC: Okay, this piece was linked by several sources, and the truth is, I had just read some George Carlin, so I was probably more aggressive than I intended to be. What I really mean is that people posting about how PHP is a bad language as a whole without citing any reasons are generally following a trend, trying to look cool, or too narrow-minded to be considered credible. And the responses I’ve seen across the net have, thus far, supported this argument.

Why? Let’s argue for a second that everything people say about PHP is true, as many of the complaints are sound.

It’s true the primary namespace has way too many functions – over three thousand, I’m told. It’s true that the function names are inconsistent, some have underscores, some don’t. It’s true that the function names are often verbose. It’s true that OOP was weak until recently, it’s true that register_globals was a security nightmare. All those things are potential issues, and all languages have them. As the “real programmers” who write Perl would never admit, reading other people’s terse Perl is often a f’ing disaster, even for seasoned Perl-ites. And when using compiled – for best performance, natch – you must update your entire site (well, all the concerned ASPX pages and DLLs) to make elementary changes.

That said, PHP is easy. Really easy. And it’s a trivial task to get a website up and running fairly quickly. And you can serve enormous amounts of traffic as proven not only by OSNews (who have been dugg and Slashdotted concurrently), but by Yahoo!, Wikipedia, Flickr, Facebook, and many, many others. And why are there so many open source PHP frameworks, apps, CMSes, etc? Because PHP is installable virtually everywhere, it’s very portable, and it’s really simple to hack up. Try installing something dependent on mod_perl (e.g. Slash or Scoop) and get back to me on the ease of the install.

The fact is, even if everyone’s fears about writing insecure code is true, the ability to make mistakes does not mean everyone does, and those who would forsake “the right tool for the job at hand” shouldn’t be trusted even to water your plants, because they are obviously nitwits. If you can’t concede that PHP can be the right tool some of the time for some situations, you shouldn’t be trusted to code or make adult decisions. No, I argue that the reason they dislike PHP is because many start with PHP and thus, admitting to liking it would make them appear to be a “noob.” It’s because they must appear to be seasoned pros. It’s the bragging rights on the 21st century.

Nobody has ever claimed PHP is the solution to everything, but it is a remarkably easy tool for scripting dynamically generated HTML. And, in my opinion and experience, it does so better than Perl, better than Ruby, and a hell of a lot better than both and JSP.

20 Replies to “An Argument for PHP”

  1. Any language has to be used enough to bend it to your will and solve your problems with your own thoughts, instead of those of the language. Bad programs come from people who let the program language solve their problems for them.

    The lines of code I write are the result of the work I do (in my mind), not the work itself.

  2. Hi Andy,

    Just read your response. In re-reading what I posted, it’s a little obvious that I had just been reading a George Carlin book, because I’m a little more acerbic than usual.

    That said, I’ve read through your site, and it’s nice to read discussion and not have it be “PHP sucks” with no actual reasoning other than the same recycled rigamarole.

    You said: “Sometimes that right tool for the job just happens to be a crappy language.”

    Whether it actually is crappy or not doesn’t automatically make it the wrong tool for everyone. I can use a great language and still write crappy code. And If I can write secure code quickly in PHP and don’t hit the “limits” that so many complain about, I can’t categorize it as an awful language. But I respect your right to choose not to code in it and feel any way you want about it.

  3. i have been saying this for a while now… most of them have never used php. the fact is most of these people are so used to restrictive languages that they do know the freedom of using a language like php and think that you can’t right good programs if you use php.

    I know php is a good choice actually better then java and asp if all you want is web application, or web front for a big java or .net app running on server.

  4. “the fact is most of these people are so used to restrictive languages that they do know the freedom of using a language like php and think that you can’t right good programs if you use php.”

    That’s an interesting position to take. Most of the PHP bashers that I know have used it far too much and are used to languages that give even more freedom than PHP.

    My personal gripes with PHP come from the language always getting in my way when trying to accomplish something. It’s the little things like inconsistent naming (or worse, inconsistent parameter order within function families) and missing concepts (like closures) that I use all the time in other languages that add up to a big heap of no-fun. Other things that bug me about PHP aren’t so much language issues as they are culture issues. The “PHP community” seems very fractured and disconnected.

    But it’s getting there. PHP seems to be asymptotically approaching the other dynamic languages in terms of community and unctionality, so one day they’ll all be the same modulo syntax 😉

  5. PHP certainly has it’s place, and in my opinion that’s small, reasonably self-contained sites.

    If you’ve got a site that needs some basic content management and a mail form, then I don’t think there are many tools that are better for the job. Using PHP you could probably hack it together in an afternoon.

    However, I’d be hesitant to use it on anything much larger then that these days. Once you get to bigger projects (a more complex CMS, web applications, etc) then you quite quickly end up with an umanageable application.

    I know there are ways to avoid that, and several frameworks are gaining traction, but I still feel there’s too many wheels being invented around the PHP world, because people have some (generally very minor) issue with the other frameworks, and build a new one.

    The Zend Framework might help that, but only if some best practices are built around it, as opposed to the current situation of “here’s a bunch of components… just, you know, bolt them together how you like”. I’ve seen too much badly written, unmaintainable PHP to get behind that sort of attitude.

    Still, as somebody who currently has to do maintanence on a Perl web application (albeit a well designed one), I’d rather have a PHP app to work on!

  6. I used PHP for a couple years. I used it professionally for about a year. (Until I found a better job.) I have attempted several times to customize horrible spaghetti PHP apps. (Sometimes successfully.) I use three criteria when deciding what technology to use:
    (1) Is it already written?
    (2) Does it have the infrastructure I need?
    (3) Will other people be able to maintain it?

    Based on repeated experience, I have decided that PHP causes brain damage. Sure, you can find smart PHP developers if you look hard enough. Sure, you can find well written PHP apps if you look hard enough. But that isn’t the ecosystem that has developed around PHP. Most PHP developers are rank amateurs that think MVC is a nice idea but unrealistic, wouldn’t know SQL injection if it bit them, fondly remember register_globals and think XSS is CSS mispelled. They may earn a living coding PHP, but they’re amateurs.

    Yes, PHP is moving away from that past. Maybe things will be better three or four years from now. But the present reality is that PHP has spent nearly a decade nurturing bad habits. I mean come on, addslashes?! What’s that about? It’s begging developers to write things the wrong way.

  7. So your argument is that PHP sucks because many people write shitty code for it?

    Sounds like sound reasoning to me.

    ::rolls eyes::

  8. The people who deserve the title are the ones who criticize PHP with no substance whatsoever. I admit PHP has some weaknesses. If, for you, they exist as limitations and you can actually explain it, great.

    But if your entire piece is that PHP sucks, period, with no context, with no real insight, then that post is worthless.

    That’s the division. Certainly, I’m not suggesting that criticizing ANY language automatically qualifies you as some sort of problem.

  9. What it really comes down to, is, people are lazy. Those who write about having to maintain code they didn’t write, are saying PHP sucks because they cant find the function somewhere in all the files that they need to edit(The grep command is your friend). So they need to find a decent IDE that has code browsing and it will show you the functions in your file.

    I have been using PHP for over 10 years now, and I know ColdFusion, .NET and Java as well personally I prefer PHP, why because its free, lightweight, doesnt need to be compiled and does everything I need it to and more.

    The naming conventions on some PHP function are a little out of whack. To this day I still have to RTFM to find a function I am looking for, but that can also be fixed with an IDE that has code completion.

    For anyone to say say that something sucks as a language is bad. I would stab my eyes out the day that I have to write something in assembly but I am not going to turn around and say that it sucks as a language.

    PHP cant possible be as bad a the nay sayers say it is or yahoo wouldn’t be using it and Zend wouldn’t have backed it and the 20+ trillion domains that are using it wouldn’t be using it.

  10. I think in the programming space you will always find good and bad developers, and they use all kinds of programming languages. PHP is there to facilitate a certain desired functionality on the web and any good developer should know when to use it or not. When working on a project, I first analyze everything that is required and check which programming language would be better suited for the task at hand, but if I can pull it off in php then I will go that route and not because I think ruby,asp,jsp suck but because I prefer php over them.

    If any one can really say a language sucks may be you need to check yourself if you understand the purpose for the particular programming language. I use a lot of different languages for various reasons , one has to understand the project requirements and the limitations for the language.

    Try to burn a dvd with your cd-rom(90x) and tell me after if you still think highly of your cd-rom….

  11. Thanks a bunch. I always hate the PHP-sucks wars. Now at least I have good arguments to win the debates. When someone throws up inconsistent naming, scoping and way too many core functions, I’ll just reply: “Hey, mod_perl is hard to install!”

    Seriously, isn’t this post the exact opposite of the “PHP-sucks” posts? And thus isn’t it as lame as all the others?

  12. Personally, I’m a little disappointed that the core PHP developers aren’t taking the opportunity to make version 6 a clean slate rewrite to try to address the current version’s shortcomings (although I totally understand why they aren’t – making the 3000+ functions utf8 compatible is a mammoth task in itself).

    PHP in many ways, really does suck. The apparent counter argument that Perl is difficult to install however is utterly redundant – the fact is that the obvious problems with PHP just shouldn’t be there any more. Unfortunately backwards compatibility seems to be a higher priority than a clean API. I have some stong opinions about that, unfortunately I don’t think airing them will make the blindest bit of difference.

    The language itself is inherently easy to learn, therefore the barrier to entry is lower than most others. This inevitably means a large proportion of new programmers end up learning how to code using it. There are a lot of very poor developers in the PHP community. There is no denying that. A lot of it comes down to the fact there is no one single well defined way of working with the platform. A good education goes an awful long way in that regard.

    It still flummoxes me however as to why people assume that this must mean the language itself is flawed. It’s a logical syntax construct, just like most others. It can do the same things the others can (for the most part). Any bad code written using it simply means the person responsible for developing it has not learnt his craft. There are VERY few situations where PHP simply cannot complete a task that another language can. I can think of a couple off hand, however both of those are related more to the webserver the language runs within as opposed to the language itself.

    I use PHP daily for my projects (of which many are on a pretty substantial scale) entirely of my own choice. And whilst there are numerous annoying quirks I’ve had to spend time adjusting to over the years, I still die a little inside when I have to go and try and build the same kind of systems in other languages. The time spent just writing variable declarations in some languages is time I could have spent writing something useful. And then it comes to deployment and things get really interesting. (Don’t get me wrong, some languages are very human friendly in the syntax department.. I’m just making a point!)

    But I digress. PHP was built to do a pretty specific job. No matter how you look at it, it does it as well or better than pretty much anything out there, so long as what it’s being told to do actually makes sense in the context. The term “garbage in, garbage out” applies to just about anything you can turn your hand to, and this is no different.

    In an ideal world, the whole PHP api would be object oriented, the whole global space would be all but scrapped, the concept of errors would be entirely replaced with exceptions and there would be a mechanism for defining your own syntax structures. Ah, if only time grew on trees, I’d be tempted to do it myself, heh. 🙂

  13. Here’s one reason why PHP has gotten a bad reputation:

    The proportion of vulnerabilities related to PHP, out of the total of all common vulnerabilities, amounted to: 12% in 2003, 20% in 2004, 28% in 2005, 43% in 2006, 36% in 2007, and 33.8% for the first quarter of 2008.

  14. “The proportion of vulnerabilities related to PHP, out of the total of all common vulnerabilities, amounted to: 12% in 2003, 20% in 2004, 28% in 2005, 43% in 2006, 36% in 2007, and 33.8% for the first quarter of 2008.”

    What exactly does this definition (“related to”) mean? Note your excerpt doesn’t say vulnerabilities in PHP so these are probably vulnerabilities associated more closely with software written in PHP rather than defects in the language itself – software written by developers who are inexperienced in writing secure webapps and like to name their projects phpThis and phpThat.

    Either which way it is good to read that the Scan Report on Open Source Software 2008 ( and also mentioned on ) commends the PHP developers for elimination of “multiple classes of potential security vulnerabilities” from their code.

  15. I read reddit almost every day, and I keep seeing the whole “PHP sucks” thing over and over. I’m not a professional PHP developer by far, but I’ve done some work in it, and overall, I’m happy with it. So, I was wondering why everyone on reddit bashes PHP all the time because I could never seem to find any real reasons. That question led me here, so I just wanted to say thank you for showing me I’m not insane. =)

  16. There is no valid use for PHP for several reasons.

    1. It is broken by design, and will never be fixed. Most of these are caused by cowboy development and adding in features too late, ex unicode, namespaces, and exception handling. These will also be problematic because the 1000’s of functions stuck in the global namespace(lulz) will never support unicode and exceptions 100%. Never

    2. The PHP team does not and never will take security seriously. Even well written and though out(lol) PHP is always vulnerable to issues built into the language.

    3. For any problem domain, you can easily find something that does it better.

    The only possible valid use for PHP is if you have nothing but static html pages and a few of them need a minor amount of dynamic content. Any other use is invalid and this use case is better served by Perl, Python, Ruby, Ajax on the front-end and anything(except PHP) on the backend.

    It has no place, and if you can’t accept it, then at least accept that you are part of the problem.

  17. “Whether it actually is crappy or not doesn’t automatically make it the wrong tool for everyone. I can use a great language and still write crappy code”

    This is true, except that PHP gets in your way if you want to do a solid job.

    You can never code a PHP app securely and quickly.

Comments are closed.