Zend Framework – my three month review

I have been using the Zend Framework almost daily for the past three months and my verdict on it is a mixed bag. I really, really wanted to like ZF three months ago when we chose to use it at work for our ongoing project and I do – with a few reservations.

I know my verdict is tainted by Ruby on Rails and CodeIgniter (I’m proficient in the use of both of them) but it’s always nice to have a reference point. I’ll get my reservations out of the way first.

What I don’t like

  • Zend Framework Validation:
    The Zend Framework has a very robust and flexible validation library. However the framework encourages validating data in the controller. In my view, validation is business logic and is thus a model function. Our current implementation actually moves the validation to the model (we added smarts to Zend_Db_Table_Row and implemented an ActiveRecord).
  • Zend Forms:
    In the same vein, ZF encourages creating complete forms in the controller. A form is HTML and belongs in the view. Furthermore we have designers working with us and as such real forms are preferable. On my own personal projects though, I suppose creating my form (including validation) the Zend Way would actually speed up my work. The jury’s still out on that one, though.
  • Learning curve:
    ZF is complex. After three months I still haven’t covered all the fundamentals and constantly have the manual open. I guess this means it’s got a lot of functionality but it also means I’m still a ZF beginner.
  • Verbosity:
    ZF has a more verbose syntax than the other frameworks I’m used to.

    Compare the following view code:

    Zend Framework: <?php echo $this->escape($this->name); ?>;
    Ruby on Rails: <%= h(@name) %>

    And the following controller code:

    Zend Framework: $data = $this->getRequest()->getPost('name');
    CodeIgniter: $data = $this->input->post('name');
    
  • Flexibility:
    The Zend Framework is flexible (perhaps too flexible?). For everything that needs doing in ZF, there are at least three ways of doing it. This means it’s highly unlikely that two applications written with ZF will be similar unlike a rigid framework like Rails or CakePHP. Comparing the source for Magento Commerce and Digitalus CMS (two open source web apps built on the Zend Framework) proves this.

What I do like

  • Flexibility:
    Yes, the flexibility is both a minus and a plus for me. ZF can be twisted to do practically anything you need it to do.
    The classes can be easily extended and have loads of configurable options. With ZF, if you can think it, you really can do it.
  • The Education:
    Browsing the Zend Framework source code is a real education in best practice PHP programming and the use of design patterns in PHP. ZF is clearly written by folks who know their stuff and really highlights the best of PHP5 programming.
  • Proper Decoupling:
    The Zend Framework components honour the open/closed principle to the letter. The classes are so easy to extend and to reuse within and outside the framework. The ease with which modifications can be made actually encourage experimentation. A case in point is the ActiveRecord functionality we added to ZF. It’s a welcome change from all the intercoupling in CodeIgniter. I actually gave up trying to get CodeIgniter models to run isolated unit tests because the models needed an instance of the CI object to work.

  • Zend Test:
    ZF comes bundled with a built-in testing component based on PHPUnit (since version 1.6). Actually that was the clincher for me in the choice of framework as the Zend’s IDE (more on this below) comes bundled with PHPUnit testing support. The test component does have a couple of things lacking (in my opinion database support would have been nice) but it wasn’t hard to extend it to our liking. Also, I’m sure with later versions, this component will be improved. CakePHP does have a better-featured test framework based on simpletest but I do like the IDE support (with code coverage) in the ZF offering.
  • Zend Studio:
    Zend Studio rocks! Zend Studio has built-in support for the Zend Framework, PHPUnit testing, code coverage, debugging and loads of other goodies to speed up PHP work. If you code PHP for a living, you owe it to yourself to check this out. The support for ZF has also eased the learning curve considerably. I still fall back to Dreamweaver if I’ve got extensive CSS or HTML code to write but I’m slowly starting to use Zend Studio even for these although DW is still way better.

Would I use ZF for my own personal projects? It depends. I actually plan to use it for an application I will be realeasing next year but the motivation to use it is based on the modularity and the ease with which the framework can be extended and not development speed. For a more focused web app, I’ll still stick with CI.

Related posts:

  1. PHP frameworks revisited – CodeIgniter vs Zend
  2. Tips for the budding PHP developer
This entry was posted in PHP. Bookmark the permalink.

6 Responses to Zend Framework – my three month review

  1. I’m sorry your experience was a mixed bag. This will be true in many cases when switching frameworks however, and your experience can help improve things in ZF.

    I want to post a few clarifications to some of your “What I don’t like” statements however.

    First, we actually don’t encourage validation in the controller; there are simply a lot of tutorials and blog posts out there that show this. We recommend putting validation close to your model, and you can do this by using Zend_Filter_Input in your model, and simply providing it with the data passed to the object. (The problem here, of course, is that we don’t have a strictly defined model — you must build your own model classes.)

    Next, the same goes for Zend_Form. The actual recommendation is to build your own form class extending Zend_Form; you then simply instantiate and use it. You can use it directly in your controller, or you can attach it to your model, where it can act both as a validation/filter chain for your model as well as a form representation of the model.

    Regarding verbosity, this is because we encourage a configurable architecture. Yes, $this->getRequest() is longer than $this->input, but it also allows you to inject your own request object easily, or provide some domain logic around retrieving it. This gives the developer more flexibility of implementation.

    Finally, I have to agree with you: flexibility is a double edged sword here. We strive to be flexible, but clearly it comes at the cost of a steeper learning curve. We are attempting to collect best practices to follow, which should assist those learning ZF, but the process is slow.

    I encourage you to contribute your ideas for improvement to the project!

  2. Colleen says:

    Yes, I am in complete agreement with this and I thought this from the get-go that the flexibility comes at a cost. I am still a rank beginner after longer than three months. well OK I was seriously ill for some time so I guess I have some excuse. I would like to be swimming in this instead of wading out and getting whacked back to shore with breakers each time.

  3. Mary Nicole Hicks says:

    I know this is an old post, but it is nice to have follow up comments…

    It is now June 2009 and I find that I am moving away from Zend Framework (ZF). This article says that ZF is flexible and I now realise that ZF is TOO FLEXIBLE!

    The problem with a flexible framework is that it requires more code to be flexible. Every call I make in ZF seems to use so much code that is not applicable to my app, but seems to exist as 1% of users may need it.

    Flexibility = More Code. More Code = Slower.

  4. Hari K T says:

    Yes , Zend framework will rock .
    Its sad that though there are many other PHP frameworks many are not using any frameworks .
    Hope in the future every one will recognize the need of framework.

    Thanks

    Hari K T

  5. David says:

    I do use ZF for pretty much all my php work now. And I find its great. Gives me all the functionality I need and can do pretty much everything I want.

    But as Mary said, it can be slow. But by adding a bytecode cache (I use eAccelerator), you can greatly increase the speed. I did this which a project I made. The cpu load of the 2xDual Core Xeon server i used went from 99% load on all cores to about 15-20%. A major increase in performance.

    My pro tip of the day :)

  6. Sergi says:

    David, the problem is the speed WITH bytecode cache. By the way, does someone today not use bytecode cache from day one of any project?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>