Choosing a PHP framework is not an easy task, especially if you have relatively little experience in PHP to know what makes a good framework or and what doesn’t, but choosing the right PHP framework for the job is absolutely critical in the long term as choosing the wrong PHP framework can lead to a number of negatives, such as longer development time, need for more experienced staff who may be hard to find and of course performance problems.  Unluckily (or perhaps luckily) when it comes to PHP there is such a plethora of PHP MVC Frameworks that it’s damn hard to actually boil them down to the final choice.  With ASP.NET for example it’s quite easy (although it’s gotten a little more complicated lately), previously there was only ASP.NET but now there’s also ASP.NET MVC, which is very different development paradigm and has it’s own catches.  However, one thing with .NET is that you need to choose how you’re going to do your data access, etc, but with most PHP Frameworks there is usually only one or two ways and they tend to do the job quite well.  So, now with this brief introduction, here’s the thoughts on Yii Framework (1.1.5) vs Zend Framework (1.11.0) vs Code Igniter (1.7.2).

Firstly, why did I decide to actually compare Yii Framework vs Zend Framework vs Code Igniter?  Well, the reason is actually pretty simple… These are pretty much the only 3 frameworks I would consider or rather they are my final 3 of like over 10 PHP Frameworks that I’ve looked at.  The reason Symfony isn’t in this list is because is too damn big and slow and unless you’re building some crazy huge enterprise project it’s not something you’d want to use as it’s slow (and why would you use it when you have Zend Framework).  The reason CakePHP isn’t in this list is because it really forces into doing things the way it wants you to do things and the moment you want to get into something a little more out of the ordinary (which often I do to improve performance) it can’t handle it and it’s also quite slow.  The reason the likes of DooPHP, Solar, Akelos, Prado, eZ Components, Seagull, WASP, etc aren’t in this list is because they’re not quite at the scale (in terms of user community) I would want them to be to actually be considered to be in this top 3 list.  Many of them are outdate and aren’t being developed further or are just akward to use and slow or short on features.  The reason Kohana PHP isn’t in this final 3 list is because I just don’t like the way it’s been written… If you’re an experienced OO developer and you crack open Kohana you just get lost… it’s all over the place.  It’s not a true OO PHP framework in that it uses the paths and all kinds of craziness to do overriding instead of just using plain old inheritance.  All this means additional file system operations and just plain ugliness, and the user community isn’t all that strong like it is for the top 3.

Now, in relation to the top 3 frameworks, being Yii Framework (my preference), Zend Framework and Code Igniter.  Firstly I’ll talk about Code Igniter and Zend as to who they’re my second and third preference as opposed to my first preference (being Yii Framework).   In fact I would have to say that Zend Framework and Code Igniter share an equal second for me as they’re just so different that it’s not really possible to say one is better than the other and should be chose over the other.  I also have to say that I have quite a bit of experience with PHP frameworks, having written some, reasearched others (including actually cracking the code open and tracing through the execution using Eclipse PDT and xDebug) and used the top 3.

Firstly, I’ll start with Zend.  Zend Framework is actually quite a nice framework in terms of it’s completeness and the fact that it is properly designed in terms of OO and lets you do things the way you want to do them without forcing you to learn some new language like Yaml.  However, I have a number of issues with Zend Framework.  For one it’s very verbouse… that is, you often have to write a fair bit of code to do something simple.  This is fine for an experienced developer, but still takes time and time is money.  The second issue I have with Zend Framework, and for me this is the real deal breaker, it is damn slow if you don’t have opcode caching, so if you’re looking to use it for something that will be hosted on a shared server and/or doesn’t have opcode caching, just forget it!  The reason for this poor performance is that the classes are split between so many files that you basically end up doing a hell of a lot of file system operations to load all the classes.  The last thing, which seems to be a deal breaker for many people is that it’s damn complex and the learning curve can be quite steep who isn’t familiar with Patterns of Enterprise Application Architecture (I strongly urge you to read Martin Fowler’s book if you want to become a good OO programmer and easily understand the likes of Zend Framework).  There’s probably a few other smaller drawbacks I could list (e.g. using text and xml based configuration instead of harnessing the power of PHP arrays for configuration like Yii), using long class names (which is needed to overcome the lack of namespaces prior to PHP 5.3) and a few other little things, probably not worth mentioning.  So from this perspective, Zend Frameworks kind of comes in as being too big and complex and that’s the reason for not choosing it.

Now for Code Igniter.  There are a few things about Code Igniter that people really love, being the huge community and the simplicity.  It is not doubt quite an easy framework to pick up for a novice, however, it also has a number of drawbacks.  Firstly, the current version of CI being 1.7.3 is still backwards compatible with PHP 4.  This means un-necessary code and all kinds of other crap.  The second thing is that although it’s quite a complete framework it actually lacks many of the things you actually want when you develop serious complex applications (not just some little amateur website). These things include proper support for templates, user controls (or widgets as they’re called in Yii), integration with jQuery (which I dare say is now the defacto standard for client side frameworks, since it’s now supported by Microsoft) and all kinds of other little things.  When you look under the bonnet you also see alot of ugliness… I mean it’s nice simple PHP code with a few unnecessary things in my opinion (e.g. check if the functions exist, using EXT to define the .php extension and appending that onto everything), naming and lack of code completion support in PHP IDEs such as Eclipse PDT and Net Beans and just plain ugliness.  Sure, it’s nice that it’s nice and simple, but it just isn’t quite there.  I would really love if there was a framework as simple as code igniter in it’s structure, but which used more proper OO techniques, the likes of Autoloaders, didn’t do unnecessary stuff like define .php in a separate constant which is appended everywhere and so on.  I’d be more than happy to manually instantiate the objects I required in some init file and do a few more things manually rather than relying on the framework to magically do them for me.  If there was such a framework I would more than happily use it for little projects, but unfortunately there isn’t one.  The closest thing I have found to this is the PHP Pro MVC framework tutorial and the framework used in OpenCart (although I thing it has some shortcomings too).  Unfortunately, Code Igniter is not this framework and falls short of what I would want for a simple framework.

Finally, I come to Yii.  I guess the thing with Yii is that it fits in nicely right between Zend Framework and Code Igniter.  It’s probably not the simplest to learn for a PHP or OO novice, but for an experienced OO developer it’s a breeze.  It has great documentation and if need be you can always inspect the code yourself.  I actually spend quite some time developing in ASP.NET and Yii feels very very similar.  It has used some of the best concepts from ASP.NET and from many other frameworks and because it’s strict PHP5 and strict OO (without crazy hacks that are typical of inexperienced PHP developers) it’s very very easy to learn and understand as long as you understand the basic principles of OOP even if you have little experience in PHP.  The thing with Yii is that it’s more comprehensive than CodeIgniter and better structured, yet smaller and more robust than Zend Framework, requiring a hell of a lot less code to get stuff done, while giving you all the same features and more (e.g. Code generation with Gii).

So, I ultimately think any experienced architect/developer will come to the same conclusion in terms of the best 3 PHP Frameworks but the ultimate choice is really going to depend on your needs and experience.  I guess the important thing with all 3 is that it’s easy to find resources, as these are probably the most widely used php frameworks these days.  In terms of choosing, if you’re doing a large scale enterprise project then I guess you might not have much choice but to go with Zend as it’s has a company behind it, it’s proven and so on, but be prepared to spend a fair bit of competent staff and hosting.  For a hobbyist or someone just starting out with PHP and not much experience with OO programming, CodeIgniter might be the way to go as it’s nice and simple and pretty easy to get your head around.  It’s also nice and light and has a very large user community and availability of resourced to learn from.  If you’re an experienced developer but don’t want to waste time writing lots of code to do simple things and don’t want to pay an arm and a leg for hosting, but want something that’s mature, well designed and nice middle ground between Zend and Code Igniter then you’ll probably choose Yii Framework like I did.

Hope my rant helps people with choosing the right framework for their needs and I’m always open to feedback.  Also, if anyone knows of a lightweight PHP framework, which doesn’t try to be too smart and is pure PHP5 OO then I’d love to know about it.  I don’t believe that such a framework needs to have stuff like ORM, ActiveRecord and all other bells and wistles, just needs to be lean, mean and fuctional.  Perhaps if you’re interested in writing such a framework I’d also be very much interested in hearing from you and perhaps even conributing.