Why I chose Zend Framework 2

Overview

For the past month or so, I've been working on building a new application for a project from scratch, and I wanted to take the time to learn another framework in doing so. I really am a huge advocate for using off-the-shelf software like drupal, magento, and phpbb when you can, but I still love getting my hands dirty. The project has gone through several massive iterations and revamps over the years since its first concept in 2003, and I finally decided on something viable a couple years ago. The project is Wow! Merchant if anyone's curious and following along. I've been using Zend Framework 1 for years, and I've grown to love and hate it. Apparently there are ways to use it for some kind of automated development, but I use it for a skeleton MVC system with a registry and library. Key up on the automation point for it'll return later.

Choosing Zend Framework 1

History

So perhaps it's best to recap some of my previous history with choosing ZF1, and surprisingly, javascript factors in quite a bit in the decision. Flashback to 2007, I'm working with a good friend at a travel site rewriting the entire application in an object-oriented manner. The previous code was worse than a patchy system; it wasn't even really functional (both uses of the word here). The site crashed, bugs were "fixed", and the site was down again, and the same bug was then fixed in the other 14 places it was copy/pasted; typical php nightmare of olde. There weren't any frameworks that we were aware of at the time, so we wrote a crude MVC-like architecture using XSL for view templates to force XHTML validation that eventually became a god-object design pattern over time. This advancement was seen as glorious to us because it was so much better than what he had, but before we even finished with the rewrite, we recognized the issues with the god-object design so we started researching possible solutions.

Enter javascript

During the same development process, I was the most adept with javascript, css, and other cross-browser issues so I was stuck with doing a lot of the front-end. We were using script.aculo.us and prototype for everything and it was making me want to pull my hair out at times, so I dug in and started modifying the libraries to figure out issues. Whenever I found a huge issue and a work-around, I'd note it down. Eventually, I had a long list of issues and I decided to either find an alternative because my fixes and changes on top of the libraries were nearly a library itself. The most annoying part I found were to be grabbing elements for manipulation. I had to incorporate all sorts of tricks to make it work, extra id here, 10 parents up, 2 siblings over, etc, and it was all tied heavily to the markup. I decided to keep chugging along with my new library and maybe release it, and I wanted to use css-like selectors. I had the project on the side for a while since the application rewrite was eating up some 80 hours per week at the time, so little time went into the javascript library, but I had nearly finished a css-like selector library when my friend started using jQuery.

jQuery

Now jQuery wasn't completely off my radar because I was doing a lot of research on script.aculo.us and the young jQuery started getting some attention, but alas, I hadn't the time to look into it. That fateful day when my friend came into the office and said, "Hey, check out jQuery. It's doing that css selector thing you're working on." At first, I had the inventive pride of wanting to have it first, but that quickly disappeared when I realized how similar the paths of the projects were and how much farther along they were. I immediately abandoned my library and have used jQuery since.

Relation to php

So the relation jQuery has to the world of php for me is that of a parallel storyline. For clients, I had written a fully custom application framework for a content management system that I was using and maintaining, but jQuery got me thinking of a possible switch for me in php. It took a while to find one I liked, and I found an "official" framework by the php developers that was sponsored by big companies so I looked into it. There were some differences here and there, but Zend Framework had a lot more features than my framework, and some serious backing, so again, I abandoned my framework for a stable third-party framework.

Competition arises

It took several years to really dive into ZF1 for use in a serious application, and coincidentally enough, it happened because I landed a client who had a lemon of an application delivered to them. The application was written in Symfony, and I spent a full week learning the framework inside and out like I knew for ZF1. I really got a sour taste over the mentality of Symfony because it was more akin to the Ruby crowd than someone like me. I then turned my eyes to the actual application and it was seriously fubar. I could go into great detail over how horrible of a mess it was and the skill it took to make Symfony, not only procedural, but somehow managed to use the application dispatch to dispatch to files that were an entire application in a single file for each page. Normally, you'd have controllers as the landing sites that would manipulate models and mappers that would be rendered in views. They somehow dumped the entire MVC stack into single files where I'd probably more appropriately call their design pattern C! for emphasis on that stupid controller. It was a lemon and had to be rewritten if redesigned (which was the goal), so although I was impressed with Symfony, I went with Zend Framework.

Why not Symfony?

cc

Seriously, that's why I decided to distance myself from Symfony. The goal was to have an application framework that can be used by non-programmers, aka developers. I've carried the developer title from time to time, but it's not exactly what I do since I'm a software engineer. I chose web applications because 1) I couldn't get a government security clearance quickly enough to work for Boeing, Lockheed Martin, or SE Jacobs (or whatever the 30th name change is they're called these days) doing missile and jet development 2) the web was a comfort zone with an exceptionally high ceiling for potential. I like working in C and D and Java and even assembly; anything really, aside from objective-c, so I like there being as little magic as possible. I heavily associated Ruby with the Rails community, and everything I saw from Rails was meant to automate development for designers, so I wanted nothing of it. Symfony's "cc" shortcut for "clear-cache" really drove home the points I didn't want to deal with. I didn't want the application to try to force me to generate all of the code from YAML files then basically compile the code. I didn't want to be stuck scaffolding by entering commands in the command line just to add a controller action or a model. I wanted to be able to edit the actual code; I am a vim guy after all so I guess it's in my nature to be that way. Sure, you can still do that with Symfony, but with the community saying the "right" way is to scaffold was a problem for me.

Choosing Zend Framework 2

I guess the real question is still, "Why ZF2?" I had some serious issues with ZF1 that were basically design flaws or shortsightedness since the intentions weren't to make it as hard to modularize or test via dependency injection. I had to use the registry heavily for things like database and cache connections, and the registry was basically a giant singleton. Singleton's are fine in some cases, but ZF1 nearly required it for everything. ZF2 directly addressed my issues with ZF1 so instead of going off looking elsewhere yet again, I kept with the same product line. Twixt the time I chose ZF1 and the time I chose ZF2, I've looked at a lot of frameworks. Every few months to a year, a new "better" framework gets all the buzz like Yii, Kohana, or Laravel. When all the dust settles eventually, there're basically two frameworks to choose from for php: Zend and Symfony. Many projects are starting to choose these two frameworks and for good reason. Magento is on Zend whereas Drupal and PhpBB are going with Symfony. Zend and Symfony are the juggernauts and your choice is most likely based on personal flavor; mine being Zend with a twist of lemon, a shot of honey, and a side of single malt clean.

Copyright © 2004-2022 MecroMace LLC