What PHP Needs!

I’ve been thinking about the things PHP needs to remain relevant. I don’t mean to say that it is becoming irrelevant, but as many people are becoming wooed by Ruby on Rails, the way PHP is done is becoming more and more … tiresome.

We like Rails because, well, it’s just cool. PHP as a language isn’t all that great, just as Ruby as a language is yet another scripting language, however the framework makes all the difference. As I mentioned, Rails is great because it take care of a lot of tedium and makes programming actually kinda fun. PHP has several frameworks available, but nothing is standard. And that’s a problem. These projects, even the popular ones, remain on the fringe of PHP development; each framework is competing with the others for users and developers. We’re playing a game of divide and conquer on ourselves. The winner might be Ruby on Rails, or whatever the next new language/framework will be.

I’ve looked at a few of the PHP frameworks out there, and Cake seems to be the one I prefer. It reminds me of Rails… as much as a PHP app framework can. The Zend framework is postured to become the de facto PHP framework due to its relation to PHP core, however it seems to suffer from enthusiasm. I visit the site from time to time and it seems like development is at a crawl and user adoption/enthusiasm minimal. I will give them some credit, though: it takes a lot to get a framework off the ground (I should know – I’ve developed my own for personal uses), and maybe once it hits the 1.0 release things will pick up (though I’m not convinced).

My second concern is how it’s so commonplace to mix PHP and markup all in the same document (business and presentation code). Sure, it works for small pages, but we should really focus on more robust coding techniques that separate the two. As far as I’m concerned, we leave this up to templating libraries, such as Smarty, one of the PHP sub projects (i.e., not part of core, but has enough clout to live at a php.net subdomain). It takes very little to get started with Smarty – just a minimal understanding of object-oriented programming (just follow the examples in the documentation), and some simple smarty template code. This really is a great system – because it’s separate from your business code you can easily change your design without worrying how it might affect other parts of your app. Second, it handles caching, custom functions, plugins. It’s a quasi framework… for the presentation layer. Going back to the frameworks discussion, it’s really a shame that they all seem to use their own template system (though there are ways to implement Smarty in them, albeit a non-standard integration). We’ll come back to this.

Finally, what could PHP really use? Besides things like making it really easy to do things (validation, input/output filtering, etc), there should be more consistency. I’ve seen a lot of people complain that things such as function naming are largely inconsistent, and thus difficult for people to learn, especially if you’re coming from a more structured language that tends to use_underscores or CamelCase naming conventions. This isn’t a big pet peeve of mine, but I think it matters to some extent if you don’t actually know the exact names of the functions you’re trying to use. At least the PHP documentation is great and super-easy to find functions you’re looking for.

As you’ve seen my theme for today is consistency and teamwork. I see to many projects doing the same things, trying to accomplish the same goals. It’s polarizing and makes it difficult for developers when they have to choose between competing frameworks, tools, libraries, etc. Remember, people like Ruby on Rails because it’s THE way web development is being done with Ruby; PHP doesn’t have that. Think about how much quicker development would proceed if every app’s filesystem was structured roughly the exact same way. All the Model files in one directory, the views in another, and the controllers in yet another. Consistency.

So this is my plea to my PHP community: Please, for our benefit, standardize. Unite. If we are going to survive as relevant and win this battle, we must work in accord. Our diverging desires and wishes are only hurting our efforts.

Leave a comment

Hey there! Come check out all-new content at my new mistercameron.com!