Posted by on in iDevelop, PHP | 2 comments

At recently concluded BarCamp Delhi 10, there was more than one discussion on frameworks, be it Javascript or PHP. There are a lot of frameworks around for just about everything – server side stuff (like for PHP, Ruby, Python, Java etc), layout (CSS frameworks) or client side frameworks (for Javascript). Over the years I’ve tried out & played with a number of them across different programming languages but since I mainly work in PHP, lets talk about that here. I wrote a similar blog post about 7 years ago which referenced a comparison done by someone else and which I used as a point of reference to choose a framework which best suited me, but times have changed a lot and so have the requirements, expectations etc.

To the best of my knowledge, today PHP has more frameworks than any other language. If we talk about quantity, only Javascript can compete with PHP for number of frameworks available. While some believe that so many frameworks result in fragmentation, I think the more the better. Existence of more frameworks instill competition and competition leads to growth and innovation. Over time the lesser frameworks fall off the grid and the age old adage Survival of the fittest is realized. 🙂

About 7 years ago came a boom in PHP, there were frameworks and there came competition. Initially it was Prado, a framework based on .NET style of having server side controls bound to UI elements. Then came 3 top dogs – CodeIgniter, CakePHP & Symfony. Of these, I liked CodeIgniter the most and used it in many a pet projects of mine for 3 very simple reasons:

  • It was very fast. It had the lightest footprint of the 3 and very tight code.
  • It was very flexible. It was so flexible, you could pretty much have your own directory structure, take M out of MVC, etc. Basically it didn’t force itself on the developer.
  • It was very easy. A developer would be able to start off with it in practically no time, it had excellent documentation written as a tutorial which required a concrete head to not get it.

Over the years CodeIgniter has kinda lagged behind the general pace of things. Or it can be said that (most) people have moved on further and faster. There are cases and arguments and arguers for both PoVs, not something that is my concern. Bottomline, its 2013 and if I want a framework to build a project on, I have following minimum requirements:

  • PHP 5.3 – I just don’t want it to have extra baggage to keep compatibility with anything lower.
  • Ease of Use – It must have low learning curve, don’t need archaic or cryptic API.
  • Good Documentation – Oh yeah, this is very important. No good documentation means crap framework & I ain’t want crap.
  • Solid Code – Should have solid code based on well implemented design patterns, half assed code is not what I want.
  • Performance – I don’t need it to be a speed demon but don’t need it to crawl either.
  • Accessible – The source code of framework needs to be accessible, I should be able to open up any part and see what’s going on.
  • Good ORM – Yes, an ORM. You might argue that Doctrine or something can always be added into a framework, but if one already has an ORM implemented out of the box then thats brownie points for the framework.

Now, this is not a benchmark on frameworks. There are a lot of them out there and most of them are quite myopic. This is an assessment of a bunch of frameworks based on my personal opinions and experiences. They might or might not be agreeable to anyone else.

If I had to pick a list, following were the candidates (on which the above mentioned requirements would be tested):

  • CakePHP
  • CodeIgniter
  • Kohana
  • Laravel
  • Phalcon
  • Slim
  • Symfony
  • Yii
  • Zend Framework

If the minimum requirements are applied to the list above, following leave the candidates’ pool:

  • CakePHP – Call it a personal bias or something but I never really liked it for a number of reasons.
  • CodeIgniter – Its not PHP 5.3 (or better), has its own set of baggage. Not something I can overlook now.
  • Kohana – It has a documentation now, however lightweight, still doesn’t score there or on ease of use.
  • Slim – Its fast and good but its a micro framework, not something I’m looking for.
  • Yii – Documentation leaves a lot to be desired for but is somewhat acceptable. But if you’re just starting out most of the times you’ll have a WTF expression on your face – doesn’t look good on my face.

After the bloodbath, Laravel, Phalcon, Symfony & Zend Framework remain.

Phalcon is something I really would try one day. From the benchmarks I’ve seen, it just rips every framework apart when it comes to performance since its not written in PHP but is written in C and is loaded in PHP as an extension, so the only code that needs to be parsed by PHP engine is the one that you write. Its a full stack framework with good documentation, straight forward API (as far as I can say after looking briefly at its docs). The only problem with it is that to take a peek under the hood I’d need to brush up on my C that I learnt in college years & years ago and which I’ve not used since.

Zend Framework is good, it has come long way since its initial release but its still slow and feels a bit clunky and outdated as far as its API is concerned. So its just a personal choice that I don’t go with it. An example:

This is just clunky code:

  1. $sql = 'SELECT * FROM my_table WHERE col_a = ? AND col_b = ?';
  2. $stmt = $db->query( $sql, array( 'value_a', 'value_b' ) );
  3. $results = $stmt->fetchAll();
  5. foreach ( $results as $row ) {
  6.     //..... do something with data here
  7.     echo $row['col_a'];
  8.     //..... do something with data here
  9. }

I’d rather do this:

  1. $results = MyTable::where( 'col_a', '=', 'value_a' )
  2.             ->where( 'col_b', '=', 'value_b' )->get();
  4. foreach ( $results as $row ) {
  5.     //..... do something with data here
  6.     echo $row->col_a;
  7.     //..... do something with data here
  8. }

The second example above is much more cleaner and better. After all, we’re not in stone age anymore! 😉

Symfony has come a long way as well, from being a pain-in-the-ass-to-use framework to a framework that can be used. Its something I seriously considered, it meets all of my minimum requirements. The door is not closed on this one, for sure.

Laravel is the PHP framework for web artisans – that is their official tagline. Like Symfony, it also meets all my minimum requirements & more. But other than that, its API is just awesome, the syntax is very expressive and you don’t need code comments in most parts to understand what’s going on. Ofcourse you should use code comments & I’m not advocating against it, I’m just saying that the API is so much readable that you don’t have to rely on code comments (generally). I watched a couple of its screencasts and I was immediately hooked, & decided this is something I want to use. It follows DRY principal quite a lot and uses a ton of 3rd party components underneath, a number of them from Symfony. If some component is well written then why write your own, better to use that – same reason you use a 3rd party framework in your project’s foundation instead of writing every line of code yourself.

So my advise would be to not go by any article or benchmark (most benchmarks are myopic and lame). If you need to pick a framework then make a list of minimum requirements that you have, what you want from a framework – must haves, should haves and good to haves – and then decide which one suits you best. What might suit someone else might not necessarily suit you.