PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend Framework 101: Zend_Loader

Article Comments (4 total)

Mark Smith, 17 March 2009
I have strong issues with Zend_Loader. The autoloader might be one of the most commonly called pieces of logic in your application. One request could feasibly load 100 classes to complete the request (including interfaces and abstract classes). Zend_Loader performs in my opinion a lot of checks that serve no purpose, and often throw exceptions which are impossible to catch. I believe the people behind Zend know that the Zend_Loader is inherently slow since they often use the class_exists() function with the second argument set to false (preventing PHP from triggering autoload). It is my personal belief that the autoloader should preform absolutely no checks whatsoever. If security is compromised to the point that an attacker can fool the autoload mechanism into loading a bad file, then it's not your autoload mechanism that is the weakest link :P All in all, I don't and will not use it and instead do one of two things: 1) Maintain a one to one relationship with file paths and namespaces, and thus my autoloader can be two lines of code: function __autoload($class) { $className = str_replace('_','/',$class).'.php'; require_once($className); } 2) Maintain a cached list of classes and the directories they live in, inside a global array. A cached list that can be automatically rebuilt by the autoloader should the first attempt at loading the class fails. These two methods are much much faster than Zend_Loader and come with very little overhead since they do not preform any unnecessary checks.

Brian Reich, 14 March 2009
Great intro to Zend_Loader! The only thing that I'm not a big fan of with auto loading is that it breaks your ability to easily track class dependencies, which you get with include_once and require_once.

Joe Lennon, 13 March 2009
Nice article - good to see some new content! Looking forward to more in-depth content on Zend Framework.

Matthew Weier O'Phinney, 13 March 2009
In 1.8, we'll be introducing Zend_Loader_Autoloader. This autoloader mechanism overcomes a few issues with Zend_Loader::autoload(), and also allows you to register additional autoloaders (for instance, from other component libraries) for use with your application. Additionally, a resource-based autoloader (think "non-standard paths") is also being added (and will register with Zend_Loader_Autoloader).
Submit a Comment
Use the following form to submit a comment for this article. You can include any required code snippets, which we will format and highlight accordingly.


Note: Before your comment appears on PhpRiot, it must be manually approved. The email address field is optional. If you choose to include it, it will be displayed obfuscated to protect it from spammers.

In This Article