PHP is a ghetto

Posted: November 18th, 2008 | Author: jonathan | Filed under: curmudgeon, development |

If you read my last article, I’m guessing you had one of two reactions. Either “Oh my science, that’s me!”, or “What an arrogant twat!”.

My second guess is that if you called me arrogant, your development language of choice for your killer CMS was PHP.

I know. I feel your pain. I’ve been there. There is a better way.

PHP was good enough for me father, so it’s good enough for me

Okay, so now I’m going to hate on PHP for a bit? What next? Sugar in your gas tank?

Let’s get one thing straight. I have no problem with PHP as a language. Well, okay, I have a few problems, but in principle I think it’s a fine platform for developing, well, anything you want. The syntax is a bit flakey, and language consistency is practically non-existent, but it’s really as good as any other language geared to web development.

I also think there are some great apps written in PHP. In my last post, I mentioned three content management systems that I use regularly. They’re all PHP-based, and I recommend them all.

So what gives? PHP is a ghetto? How come?

PHP is too easy

While it will take me a little while to justify it, my conclusion is simple. PHP is far too easy to hack on and get fast results.

You know what else is too easy? HTML. Let’s take a little analogy trip back to the late 90s.

Back in the day, HTML was a horrendous tag soup. “Progress” was measured by browsers adding proprietary tags to a badly-enforced spec that nobody cared about. We all laid out in tables, we all used massive sliced images to get our message across. Our sites were inaccessible and unsearchable.

But who cared? It was easy to build a website. Fire up Front Page, hack about in Photoshop for an afternoon, and boom - one corporate intranet coming right up!

Of course, you could follow the standards if you wanted. You could create great sites without resorting to the nasty tables, but if you did so you were an one of those guys - what was the point?

The point, of course, was maintainability, with an added bonus of learning a whole load about how the web was supposed to work: semantics, presentation separation, scalability, inter-app communcability. These days the cool kids call it “Web 2.0″.

Thankfully, the sort of table-driven web design that we saw back then is dying a slow, lingering, but ultimately satisfying death. Designers who still think in terms of CSS being “that new thing that nobody really uses” aren’t occupying many high level positions any more, and it’s all a bit more disciplined a discipline.

PHP is still amateur night

Let’s haul our analogy back on track. What does this have to do with PHP? The problem is that while the folks running the show at php.net are desperately trying to enforce some standards, and generally discipline up their users, the users are having none of it. PHP4 just won’t die, and there are still a lot of professional PHP developers out there who haven’t moved beyond a few bits of PHP injected into flat files on their server.

PHP is great for quickly adding some functionality to a flat site. That’s how most of us got into building “PHP apps” in the first place. A file here, a login page there, some admin forms and suddenly we’ve got an app! It’s untestable, unmaintainable, but it’s small enough that we don’t care.

Except we then get adventurous and start hacking at some sort of “framework” idea that we have, without realising that we’ve crossed over to the point where we really need some computer science understanding here. Design patterns? What are they?

Suddenly we have hundreds of .php files in our public_html directory, each one slavishly copying the authentication header include to make sure the right users get to administer the site. Adding a new section? Fire up the FTP client, create a new directory, and make four copies of the “page” script.

We might even get creative and use .htaccess to start hacking up our URLs to look nice.

But we’re still just using glorified server-side includes to activate our pages.

Go pro

Most of the good, object oriented, application-thinking PHP developers I know only became that way because of one of two things in their careers:

  • They came to PHP from a comp. sci. background
  • They left PHP to program in a different language, and came back enlightened

This is one of the main reasons that I try to wean PHP developers off PHP as fast as possible when I meet them. I don’t care if you use Rails, Django, Zope, Erlang or frigging Perl (okay, maybe not Perl) - just get out of the PHP ghetto, and see how the big boys do it.

It’ll seem weird at first (”There’s only one file in the public_html directory!!”) and you won’t like it (”I could do this SO MUCH FASTER if I just wrote some inline PHP to process the form submission”), but gradually you’ll start to see all the wins you’re getting (”You mean I don’t have to instantiate the database connection?”) and the time you end up saving (”Wow, all my HTML is bundled in a neat package, and I can drop in a new template any time I like!”).

You’re then free to come back to PHP and start coding like a real programmer. You’ll have a much greater appreciation for how it all works, and that a little discipline saves a lot of time.

Why the venom?

The last couple of posts have been pretty vitriolic. They say we hate most in others the faults we see in ourselves, and I’ve recently been reminded of my “bad old days” a few years ago where PHP was my only language, and I loved Rails but didn’t want to learn Ruby.

I’ve been working recently on a legacy project from those days, and realise how far I’ve come. I hope this post and the last one might save someone else the pain.

PHP is bad shit, kids - just say no.


4 Comments on “PHP is a ghetto”

  1. #1 John Malcom said at 12:35 am on March 27th, 2009:

    I would agree that PHP is so easy that to find talent can be difficult, the developer pool really is watered down. But I do disagree with you; PHP is an extremely well performing scripting language with full OO support. Its not about the what its about the how. Poor developers can find ways to pollute a code base even within a well designed framework or the constraints of an all OO language. A good developer however, can write elegant code regardless of language as long as the right tools are available ( ie MVC, testing suite, continous integration, build ste, etc… )

    Perhaps you could evaluate this stack and post again…

    Zend Server CE ( apache, mysql, debugger, auto cache )
    Zend Framework ( MVC )
    PHPUnit ( testing )
    Phing ( building )
    Xinc ( continuous integration )

    I’ve found that the combination of these tools makes PHP just as powerful as rails and spring ( which i love as wel ).

  2. #2 admin said at 7:55 am on March 27th, 2009:

    Thanks for the feedback John.

    I think you’re missing my point, and I actually agree with your disagreement in the fifth paragraph of my article. PHP is essentially as good a language as any.

    You say “Its not about the what its about the how” and I agree. The issue is that when “the developer pool really is watered down”, so too is the understanding and use of the language.

    It’s a bit like judging, say, English by its dictionary instead of by its usage: the two paint a completely different picture of what it’s like to speak English.

    I certainly agree that “A good developer however, can write elegant code regardless of language as long as the right tools are available”, but as you yourself point out, there are far fewer “good developers” in PHP than, perhaps, in some other languages which have a less diluted developer base.

    Perhaps I should change the article title to “PHP Development is a Ghetto”?

    Finally, I’m aware of all the frameworks you list. That’s because we’re “good developers” ;-) Most “PHP Developers” would look at you funny even if you just mention “testing” or “MVC”, and think that Zend are just the guys who designed the phpinfo() page ;-)

    I guess my central point is that, of course, a great developer can bend any language to her will elegantly. PHP, however, encourages poor development practise simply by not discouraging it, and so produces poor coding standards by default.

    Other languages don’t. By default, I don’t trust PHP developers who only have a PHP background for precisely that reason. If a developer has gone through other languages and come back to PHP, well that’s their call and I respect them for it.

    I think, fundamentally, we agree. You’re just arguing against a point that I didn’t try to make.

  3. #3 Flash said at 4:31 pm on July 6th, 2009:

    Perfect!

  4. #4 Ryan said at 10:09 am on September 11th, 2009:

    What makes this funny is you’ve just described me and how I use PHP perfectly! However I don’t call myself a Programmer and have no intention of becoming one… stuff like RoR just goes way over my head.

    I’ve been designing and building sites for a while now (5+ years) and I’m still looking for a programmer to partner with so I can leave the server side stuff to a professional and not hacking stuff together!

    I’m beginning to doubt this will ever happen :(


Leave a Reply