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

Autoloader Conventions and Design

Zend Framework's autoloading support, provided primarily via Zend_Loader_Autoloader, has the following goals and design elements:

  • Provide namespace matching. If the class namespace prefix is not in a list of registered namespaces, return FALSE immediately. This allows for more optimistic matching, as well as fallback to other autoloaders.

  • Allow the autoloader to act as a fallback autoloader. In the case where a team may be widely distributed, or using an undetermined set of namespace prefixes, the autoloader should still be configurable such that it will attempt to match any namespace prefix. It will be noted, however, that this practice is not recommended, as it can lead to unnecessary lookups.

  • Allow toggling error suppression. We feel -- and the greater PHP community does as well -- that error suppression is a bad idea. It's expensive, and it masks very real application problems. So, by default, it should be off. However, if a developer insists that it be on, we allow toggling it on.

  • Allow specifying custom callbacks for autoloading. Some developers don't want to use Zend_Loader::loadClass() for autoloading, but still want to make use of Zend Framework's mechanisms. Zend_Loader_Autoloader allows specyfing an alternate callback for autoloading.

  • Allow manipulation of the SPL autoload callback chain. The purpose of this is to allow specifying additional autoloaders -- for instance, resource loaders for classes that don't have a 1:1 mapping to the filesystem -- to be registered before or after the primary Zend Framework autoloader.

Zend Framework