Developing software in the Real World

Goodbye Zend.php

For those of you not following along on the fw-general mailing list, the Zend.php file along with its Zend class has now gone! This is good news as the Zend class was schizophrenic and provided functions responsible for file loading, registry, debugging and version information! Another side effect is that the entire Zend Framework is stored within the Zend directory making those who use svn:externals on their lib directory happier.

We now have new classes:

  • Zend_Loader (holds loadClass(), loadFile() etc.)
  • Zend_Debug (holds dump())
  • Zend_Version (holds VERSION constant and compareVersion())

and Zend_Registry now has a static getInstance() method.

Another change is that the static filter methods in Zend_Filter are gone to be replaced with the Zend_Validate and Zend_Filter family of classes. Now, each filter is its own class and you can chain them together using the new Zend_Filter class. It’s much more flexible, but feels much more verbose too, especially when you have to instantiate a lot of different filters for filtering a form. I suspect that someone will come up with a nice solution to filtering forms at some point though. Also, Zend_Filter_Input is also gone, though this isn’t surprising as it didn’t work with the newer MVC code anyway

Top Tip: Don’t bother with Zend_Filter_Int. It’s faster and much less typing to just cast to an int directly!

I’ve updated the subversion code of my tutorial to work with the latest svn of the Framework, for those of you who may be interested. Be aware that in anticipation of some other stuff that Matthew is working on, I’ve rewritten it to use header/footer php files for each action’s view template. Another change I’ve made is to remove the dependency on hard-coded URLs for the CSS files, href and form method attributes. I now use getBaseUrl() to collect the correct path and go from there and so you can now run the tutorial from any directory and it’ll “just work”! I’m unlikely to update the tutorial text until 0.9 is out though as there is quite a lot happening this cycle.

The transition work was quite easy:

  1. Replace include "Zend.php" with include "Zend/Loader.php"
  2. Replace all calls to Zend::loadClass() with Zend_Loader::loadClass()
  3. Replace all uses of Zend_Filter_Input with a call to the correct Zend_Filter_Xxx class and
    use $this->_request->getPost(‘{name}’) to get the data from the form.

The main gotcha that I found was that the dump() function doesn’t work until you remember to Zend_Loader::loadClass(‘Zend_Debug’)! That’s fairly obvious really, but does make using autoload that much more worthwhile :)

Update: Andries Seutens has more details!

6 thoughts on “Goodbye Zend.php

  1. Thank you for this! From what I can see there isn't anything about this in most of the ZF tutorials (unless I just blatantly skipped past it!). Saved me from pulling even more of my hair out…

Thoughts? Leave a reply

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