A (fond) farewell to Zend Framework

March 24th, 2012 | by | freesoftware

Mar
24

I’ve been a Zend Framework user for a while. I’ve been using PHP long enough to appreciate the benefits of a good framework, and developed a number of sophisticated applications using ZF, to have grown a certain fondness for it. Although it has a reputation for being difficult to get into, being slow and being overly complicated – not undeserved accusations, if we’re being honest – there is something quite appealing about it. Well, was, for me at least. ZF 1.11 looks like the last version of the framework I will be using.

Why? The simple answer is ZF 2.0. Having been busily built over the past couple of years one way or another, a number of betas have been released and it looks likely to me that an initial release is a few months away. At this point I need to make a decision about my future use of the framework, and I don’t particularly like what I see.

Let’s be quite honest about one thing up-front: I cannot claim to have done any substantial amount of work in ZF 2.0. The criticisms within are all personal opinion based on little more than the most itinerant tinkering.

That said, I actually don’t feel like much of what I’m about to say is unfair, for one simple reason: I have tried to like ZF 2.0. There are of course other PHP frameworks, and I don’t really need to name them, and many of them are initially much nicer to get started on than ZF. Despite all that, I got quite happy with ZF1, and indeed approached ZF2 with the idea that it would take a similar amount of effort to learn to like it. I have attempted to apply that effort. I have failed.

Much of what I think is wrong with ZF2 you can quite obviously see in the ZendSkeleton example application. Now, of course, the example applications for most things are pretty poor: every JS framework has a To-do app, and things are generally chosen to show off the best features of the framework in their most flattering light. That’s actually the first thing that hits me about the skeleton application: it’s deathly, deathly dull, but there’s a pile of code needed to get you to that point. The sheer amount of boilerplate needed to get much further than ‘Hello World’ is incredible, and of truly Java-like proportions.

Generally, I like my frameworks opinionated. I like having a culture, or an ethos, which come through as a set of guiding principles for the developers of both applications using the framework, and the framework itself. And ZF certainly is and was opinionated. I suppose at this point, I find that my opinions differ with theirs too much, and that’s an issue.

The first opinion I would cite is the use of dependency injection. Now, I get DI, truly I do. I even like the idea of it. I can see how it would be useful, and how it could add a heap of value to a project. But there is “useful feature” and then there is “koolaid”, and DI in ZF2 is alarmingly close to the latter. As a case in point, just take a peek at the module config for the skeleton app.

The comment at the top of the file first sent shivers down my spine – “Injecting the plugin broker for controller plugins into the action controller for use by all controllers that extend it” – it’s the kind of enterprise buzzword bingo that again, sorry people, sounds just like a Java app.

And as you progress through what is supposed to be just a bit of config for a simple application, wading past the router config and various pieces of view configuration, you’ll see the thing which just turned me right off – ‘Zend\View\Helper\Doctype’. Seriously? A fragment of view code to manage the doctype? As if this is something you can just change at runtime? “Oh yeah, we built it in HTML5, but I can just downgrade to HTML4 by switch….” sorry, no. Doctype is totally fundamental to the templates you’ve written. This is so far from application config it’s not funny.

Other stuff I can’t abide: the default file tree. Did you think application/controllers/IndexController.php was bad enough? Now you have module/Application/src/Application/Controller/IndexController.php. I do get the reason for this, but again enforced modularisation – ZF1 supported modules too without forcing it.

I know how observers might respond to this: it’s a skeleton app. It’s supposed to be showing a set of best practice, you can cut corners and make things simpler. Except, this isn’t true: there’s already a whole load of corners cut. Just look in the layout; there’s a pile of code at the top of the template. Isn’t the view supposed to be where the code lives?! I would have most of that crap in my Bootstrap.php as-was, I can’t believe people are advocating throwing that in the layout template now (and I’m sure they’re not). But there it is, cluttering up the layout, when it really should be refactored somewhere else.

This is the issue. The skeleton app does a whole heap of things just to do nothing except chuck Twitter bootstrap on screen. I am, of course, willing to be shown how all this up-front investment will pay off in the end – but right now, I really do not see it. The more I look, the more I see things which will just require more and more code to get working – a constant investment throughout the life of a project, without any obvious pay-back for it later. As a rule of thumb, whenever I’ve used a framework before, the skeleton always looks pretty good, but a production app gets entirely more complex and hairy. Things don’t improve, generally, at best they stay as-bad. I would worry that a ZF2 app would just explode into a sea of classes entirely unnavigable by a junior programmer, held together by a DI system so abstract they would have little chance of properly comprehending it.

This is really sad. ZF1 had a number of shortcomings which I thought ZF2 looked on track to tackle – and, in all probability, has tackled. The REST controllers in ZF1 were complete bobbins, and ZF2 looks like it has that right. The Db layer in ZF1 was actually quite good, but ZF2 looks to have improved on it. PHP namespaces are of course ugly as sin and ZF2 embraces them, but they make sense and I could potentially learn to love them. But my gosh, just look at the quickstart. Remember, this is the “get up and running as fast as possible” guide for people who already know the language and just want to get cracking.

What is bad about it? Well, 12.2.2 is the start of the “you’ve already installed it – let’s get coding” section. First item on the todo list? “Create your module”. This involves downloaded the skeleton, copying bits over, and being told all is well. 12.2.3, update the class map for the autoloader, using the correct namespace, ensuring configuration is enabled and being lenient with the autoloading (let’s both you and me pretend we understood what on earth this section was trying to achieve).

12.2.4, create a controller. Oh my god, I don’t want to know what Zend\Stdlib\Dispatchable is there for, or why I might pick a REST controller because the quick start doesn’t cover REST. But no fear, we have a basic controller, it looks like this:

namespace\Controller;

use Zend\Mvc\Controller\ActionController,
    Zend\View\Model\ViewModel;

class HelloController extends ActionController
 {
   public function worldAction()
     {
        $message = $this->getRequest()->query()->get('message', 'foo');
        return new ViewModel(array('message' => $message));
     }
  }

Unfortunately this reminds me again – I hate to use the J-word – of all the geek Java jokes. Boilerplate object-this and method-other-thing-another-method-that().

I so want to be interested in ZF2, but it’s about as far up the corporate enterprise architecture-astronaut ladder as I have ever seen PHP climb. And honestly, if I wanted to program Java, I’d use Java. And then I’d download Play or Scala and actually enjoy it. But for PHP, no. So, adieu, ZF. It has been nice knowing you.

Authored by

76 Responses to “A (fond) farewell to Zend Framework”

Show / Hide Comments
  1. James says:

    I have never seen a PHP framework so complicated like ZF2!

    There are too many slogans in it such as Service Manager, Event Manger, Module Manager, Path stack, Input filter, Dispatcher, Listener, Factory, Strategy, Renderer, Helper, Plugin, Loader, Resolver and so on.

    How can we understand ViewJsonRendererFactory, InjectViewModelListener, ViewHelperManagerFactory,
    SharedEventManager, LocatorRegistrationListener,
    ModuleResolverListener, ViewTemplatePathStack,
    AggregateResolver?

    It’s not a framework for a developer, it’s a text book about design pattern. But if I want to learn design pattern, I’d like to read Gang of Four’s book which is much easier and understandable.

  2. fred says:

    my explanation is that the dev took more time than expected and documentation is not as complete as expected.

    i worked with ZF2 beta 3, bet 4, rc1 , rc2 and now with final release 2.0. everytime i changed version, some things were broken, because some method names, class names, config names changed… very annoying… but playing with beta is a special game for special people :) . if you don’t want to play this game, you just have to wait for framework to stabilized and documented… :)

    What else can i say ?
    yes, ZF2 need some time to learn, basicallyu because of the lack of code samples. i hope this to better in coming months.there’s a web site, http://modules.zendframework.com/, where you can find different modules. this site is supposed to get bigger in the future…
    yes, ZF2 is complex. but connectors with third party apps seem quite good. i use doctrine 2 without much trouble.

    hope this helps…

  3. Andy says:

    You are so right! ZF2 is so over engineered; it’s as if someone was thinking “hey, this could be super cool!”, rather than thinking if it’s really necessary or friendly for all the people trying to learn it. If you are going to make something so incredibly complicated, the least you can do is to make proper documentation (by documentation I mean guides and tutorials). Right now, all I see in the skeleton application is super big and highly complicated configuration arrays.

  4. [...] Alex Hudson has a good write up on Zend Framework 2 and his thoughts on the matter, personally I’ve tried numerous frameworks in the past and the one I found easiest to code with was Code Igniter. [...]

  5. Trent says:

    Just checked out ZF2 – no longer considered beta or alpha or whatever; and it’s still complex beyond belief.

    Played around for a while, and can’t see any benefit of continuing with the learning curve.

    I’ve written a small framework which runs in fractions of the time as ZF2 and does 100% of what I need it to.

    I’ve found projects like these tend to get “Geekified” pretty quick. A few years on, and this bad boy is one bloated, complex framework.

  6. Yii is the way of the future for PHP frameworks. Thin layer of classes that are actually useful. Extremely extensible *using techniques you already know* — regular inheritance, etc. — and good implementation of patterns like mix-in pattern (Behaviors), events, etc.

    Zend is death. Yii is life.

  7. samsonasik says:

    $this->getRequest()->query()->get(‘message’, ‘foo’);
    is no longer used, you can use :
    $this->params()->fromQuery(‘message’, ‘foo’); for security purpose.
    or just $this->params(‘message’,'foo’); for lazy type.

  8. GraXXoR says:

    As a part-time PHP programmer in and around the end of 2009, I found ZF1 + Doctrine to be refreshing (no, really), if a little frustrating to get going. Once started, it took me through my “yoof” as an OO programmer and allowed me to create a website which has run trouble-free for three years…. So trouble-free, in fact that I never went back in to take a look until I decided to redo it with new features a few months back.

    Seeing as ZF2 and Doctrine 2 were now go, (ZF 2.0.4dev as I speak) I thought it would be time to take the plunge….

    I remember all the inconsistencies and cracks in the v1 product and all the gumph stating that ZF2 would fix all these weirdities.

    Well, colour me underwhelmed, but ZF2 has moved from 500 Pound Gorilla to 1500 pound Godzilla. It’s monstrous. I spent several days with the “Quick Start” before I relased I had no clear idea of what it was I was doing… Half the changes I made resulted in a white screen requiring a stack trace to sort out…

    I remember ZF1 documentation being an unholy collection of “Man” pages for each component, until I found Akrabat’s excellent guide and ZF1 starter app! It was really easy, logical and step-by-step documented. A pure pleasure to work through….

    ZF2′s skeleton app? Not so much.

    What the heck is that? A demo? As someone who worked on ZF1 for 18 months. I didn’t expect ZF2 to be just as bad as starting with a new framework from practically zero.

    It was then I went online to garner some opinions… It turns out that plenty of people are in the same boat… “If you thought the documentation for ZF1 was bad, just try ZF2!” “ZF2 ushers in a new level of undocumentation.” “Docs? Docs are for pussies!” were a few of the more colourful comments I came across that would have made me laugh were I not trying to get my head around ZF2 at the time.

    Sure, I understand the need for solid OO based frameworks, but ZF2 has now progressed beyond the realm of the interested programmer type and firmly into Enterprise land… If I were getting paid to use it, or thinking of a career as a web devolper I would tackle it without question, but there are far simpler alternatives for the personal/small business user with only a limited amount of time in his budget.

  9. I’ve been developing in PHP for a decade, and I am a huge fan of ZF1. I spent half a day going through the ZF2 tutorial, and I ended up Googling “Zend Framework 2 disaster”.., and that led me to this blog.

    What is this !? (ZF2) Seriously… I really hope ZF1 will be continued to be supported as long as ZF exists. It is a very sad time for ZF users..

  10. Greg says:

    I am starting to feel the same way! In fact, I think its so complicated, they need an framework on top of the framework just to abstract the framework underneath!

    The setup isn’t bad, and skeleton is loaded easily now, but, man… you are sooooo exactly right!! I just tried to add a new controller and matching view-phtml file, and quickly discovered the module.config.php file listing the routes. I can’t believe it! Just looking at that thing makes my eyes cross! DI sounds truly awesome for *some cases* but, I want a framework to make development easy. I don’t want to keep adding to my work load and need to setup a huge config just so I can drop in new controllers and view. So I predict, someone will build a new *Module* for ZF2 to replace the skeleton/mvc setup that will be nice-n-easy to use, while still harnessing the power underneath for the few times you need to customize something. It will literally be a framework built on a framework.

    Those times when you need something advanced and customized are like 2-percent of the time! Rest of the time, you just drop in views and controllers, a form object or two, and maybe some db table objects and custom data view classes. That’s why I like ZF1!!! Was hoping they would have kept that same flexibility, but not adding to manually configuring things.

    BTW, I tried quickly to use Node.js, and I am excited to see what comes of it in the next couple years. As for now, its just too new and too many things just didn’t work and I’d have to rebuild way too much that ZF1 does for me with ease. Biggest issue I ran into was not enough people running into the same problems, meaning, Google can’t find my issue, which means I am stuck scratching my head. So trying to get what I have in ZF into a Node+MVC system, that’s going to be too hard right now. Some of the Node/Express/Jade stuff looks really awesome though.

    I love Python though! Once in a while I get to work on little server programs/scripts, and always have fun with it. I might just have to play with Django. But I’ll still hack away at learning ZF2 for a while, maybe some of it will actually be helpful. Not impressed with the module.config, really not impressed. That stuff should be automatic for what I need, which, in ZF1, it was for me. (the routes, controllers/actions, etc)

  11. Greg says:

    Hello Alex,
    Just wanted to follow up after my own rant post last night. I suppose you’ve moved on to other frameworks since we’re several months after your posting, but I wanted to say, its looking not so bad now.

    Yeah, the deep structures and explicit naming is annoying, but I think I won’t care in time. What is annoying me most is the module.config.php. Its not as bad as I first thought, but you do still need to set your “invokables” for each view Controller. Not a big deal, but not what I am used to.

    I spent a little time reading docs on Symfony, CakePHP, and CodeIgniter. The of the three, Symfony looks most appealing, and in some ways it’s like ZF2 with the new namespaces. I don’t like idea of templating engine, and rather just use layouts the way ZF does. Symfony has some nice helpers and easy ACL setup according to docs. But now, since I have a simple MVC module running in ZF2, I think I’ll stick with it. I am most used to the ZF-way, and even though ZF2 is a quite different from ZF1, its still ZF and I like the open flexibility of it.

    Now… on to makeing ACL’s and DB adapters work the ZF2 way!
    Good luck!

  12. kc42 says:

    Hello Alex, I couldn’t agree more, having enjoyed using PHP for over 12 years, Zend and the Java corporate world keeps invading our space. Zend wants the big bucks of Java, will it succeed? I hope not ( death by PHP association! ), we’re not that desperate or that greedy! Give me CodeIgniter or Cake any day.

  13. Michel says:

    Thank you so much. What you say mirrors my feelings of zf2 quite well. I’ve used zf1 since first beta and even in zf1 I had to replace or overwrite large portions of the code base to get the required performance out of it. Zf1, in many cases, still was a good guideline on how to implement generic software patterns in PHP, thanks for this to the zf team.

  14. LoneShooter says:

    Hi Alex,

    This article was written when ZF2 was in beta stage.

    Have you tried the stable ZF2 release? And, have you changed your opinion?

  15. BPile says:

    I moved from ZF1 to Yii framework, which now just feels right for me. Thank your for pointing out ZF2 problems, I was about to give it a try so I enjoy reading hands-on experiences.
    Your post is 3rd in a row and so far none of them convinced me to bother about it :)

  16. crivion says:

    I personally hope they will skip any zend framework 2 updates and go to a brand new simplistic zend framework 3.

    This is a total nightmare and I am very happy not to be the only one finding it a total crappy mess.

    What a dissapointment !

  17. Malte says:

    Hi Alex,

    I can totally understand where you are coming from in terms of complexity….

    However, after 3 months of using ZF2 in a new project (having used ZF1 before), I have to say that I am totally in love with it. Sure, there was a lot of head scratching and frustration involved (the documentation was basic and getting good background articles was difficult), but after the initial pain I can now see several goodies:

    First of all, it seems that the old DI container is still there but is replaced with a simpler IOD mechanism, the ServiceLocator. Having this means we can now delegate the responsibility of creating complex class structures to one place only. Made unit testing sooo much nicer as now classes do not have to know how they have the dependencies injected.
    Also, there is not a singleton in site, having the service locator means we truly have not got any global data in place any more: When I tried using my own Controller test cases in ZF1 using a web-based test runner using, well, ZF1, the global data and singletons meant that it was virtually impossible to separate the parts of MVC under test and the ones running the test. This is not the case any more in ZF2.

    Our new application is as far as I can tell so far, and subjectively speaking, the most beautiful code that I have been involved with. ZF2 has enabled us to add functionality truly horizontally using the new Event-driven way without modifying existing classes…

    Time will tell, but so far, so good, after initially more coding up-front it seems that now a lot more can be achieved in a lot less code……

  18. Iain Collins says:

    I’m about late to this article but yes this, really well covered Alex. We reached the same conclusions at work around the same time you wrote this.

    We have multiple sites and quite a bit of code, so likely to stick with ZF1 due to ongoing work an inertia but I’m not sure we will ever go to ZF2 (i.e. probably something else all together at some point).

    ZF1 was good enough that it made the boilerplate worth it – it was minimal and kept large projects on track. ZF2′s added complexity for no apparent value (And screwing up the configuration system – .php files for configuration? That will end well…) has turned it into something I don’t want to use.

    I don’t want to make lame jokes at the expense of Java (specifically the “Enterprise” flavour of Java), but it really rings true. It’s much more complicated and much less sophisticated.

  19. Manachi says:

    I feel a bit guilty commenting on the framework before I’ve had sufficient development experience in it. But based on the documentation, tutorials, code and reviews I’ve read & seen so far, I agree with you 100%. I’ve been a developer for a long time, and used numerous different languages, frameworks and environments, and so far ZF2 seems over-complicated, over-engineered, and flooded with buzz-words. And to be honest I find it hard to believe that the the complexity would actually pay off with real-world benefits.

  20. wagner says:

    as a freelancer I like to keep my self up to date, and after spending a couple of days looking at zf2, i have to say i agree with you alex.

    I will be sticking with zf1 until i have no other choice.

  21. Richard Knop says:

    I see lots of comments agree with the conclusions in this article. Let’s offer a different opinion for a change.

    I have been using Zend Framework 2 for cca half a year. Company I work for has decided to use ZF2 for its upcomming new platform. Couple of points:

    1) default file tree:

    What other approach would you propose in order to use namespaces properly? I prefer the new file tree and the way each module is enclosed in its own namespace.

    It avoids name conflicts, allows you to have models with the same name without confusing the hell out of people and makes the top of each file more readable.

    The “use” statements are very clear and tell you exactly what other classes are needed and where this classes are coming from.

    2) “As a rule of thumb, whenever I’ve used a framework before, the skeleton always looks pretty good, but a production app gets entirely more complex and hairy.”

    It actually gets much easier as your app grows and becomes more complex. At least it does for me.

    There will often be lots of similar business logic across modules, similar forms, similar validation and transformation of data before pushing it to APIs. If you abstract it out in the beginning, it will pay off in the longer run.

    The same is with views / templates. Most applications will have repeating patterns of HTML reused across the whole application with minor modifications (forms, navigations, wizards, widgets, paginations). If you abstract this out into partials and helpers you will save a lot of time in the future.

    After few weeks you will already start seeing benefits. A new requirement will come and you will find out that similar (not quite the same) functionality is already in place. Just extend few classes, overwrite few methods, reuse few partials with slightly different parameters.

    Amount of boilerplate in the beginning is quite huge with ZF2, I agree. But it pays off soon enough and with passing weeks you find out yourself not writing relatively few lines of code to implement seemingly complex new requirements.

    I also love the new forms and the fact you can use annotations is awesome. Using annotations, I find forms in ZF2 to be much cleaner and more straightforward then forms in ZF1. And finally the Decorator pattern is gone.

  22. Richard Knop says:

    And one more thing, the DI is really useful. Service Locator pattern allows you to define complex creation of objects in one place. You can put all your factories there.

    And suddenly your models can become completely dumb and unaware of other classes which makes the code cleaner unit testing easier and cleaner as well (using mocks and stubs gets easier as well imho).

  23. Richard Knop says:

    Composer for dependency management is sweet as well. Anyways, enough from me. Three times and enough :)

  24. Tom says:

    I am going to have to agree with Richard here. I have done extensive work in ZF1, and have recently been working on a huge project in ZF2.

    Yes… it took a little time to get used to the differences between ZF1 and ZF2. Once you take the time to understand those differences though, you might find the ZF2 is actually rather nice.

    I suppose that also assumes that you are used to OOP, Design Patterns, and using a framework. If you want to circumvent the frameworks you are working in, or don’t really understand design patterns and OOP principles, you probably won’t like ZF2.

    The author of this article openly admits that he hasn’t really done much other than poking around in ZF2… I wouldn’t take his opinions as gospel.

  25. edu says:

    Have been ZF1 user for years and its time to say goodbye to ZF2… sad

  26. ummi says:

    alex writes as from my heart, I have 15 projects written with ZF1, i liked ZF1. the expectations for ZF2 was great. unhappily, I lost a lot of time for divesre beta and even stable releases from ZF2. there is hardly no any module in http://modules.zendframework.com that is not broken.
    ZF2 will be like symfony2, but is not. symfony2 has much more stablety, quickness, flexible configuration and command line code generation and the things are not forced as in ZF2. maybe ZF3 can it! but then without me, sad.

    it is easier and more efficient to migrate from ZF1 to symfony2 rather than to ZF2.
    very, very sad! squandered a lot of time in ZF generally.

Leave a Comment