I’ve been writing code in PHP for a long time now, both for my own projects and as a freelancer. I’ve seen well written code and truly horrific code and everything in between. Much of the work I’ve done for my personal projects has been using a framework that I’ve built and added on over the years, my PHP Foundation Classes.
Lately, however, I’ve found the need to use a more generic framework and have evaluated Yii, Symfony2, CakePHP, CodeIgniter and of course the Zend Framework.
After examining them all, I narrowed down my focus to Yii and Symfony2. I really like Symfony2 because it integrates well with the Doctrine ORM. I’ve used Doctrine v1 extensively in other projects and it is fantastic. This would make Symfony2 an obvious choice for me, but there is one thing about it that I just can’t get past: Annotations. Annotations in Symfony2 and Doctrine2 are what are keeping me from using it.
Annotations are specially formatted entries in the comments of a source file that control its runtime behavior. Comments should never have any impact on code behavior. Ever.
Now, Symfony2 and Doctrine2 can also be configured and controlled via XML or YAML files, but since they’re not as “convenient” they’re not used nearly as much as annotations in the core library or the third party modules.
Annotations are great for things like auto generating documentation, but shouldn’t be used for code control.
For certain projects, I also use SourceGuardian to encode and license my projects. Annotations by their definition are incompatible since SourceGuardian strips comments as part of its encoding process.
Yii has a very clean solution that accomplishes the same thing that Annotations do. The main.php configuration file. Using arrays to configure the application is extremely fast and clear. To change a route or URL I don’t have to search for YAML, XML or source files, I just go to the main.php and edit it. Centrally located, fast, and convenient.
I still love Doctrine v1. I use it in several projects and it integrates nicely with both Yii and my own foundation classes.