开发者

Why these 2 lines in Zend Bootstrap autoloading function

I've seen examples that has this block of code and other examples that didn't have the 2 lines commented MAYBE NOT. What exactly is the purpose of these 2 lines?

$moduleLoader = new Zend_Application_Module_Autoloader(array(
    'namespace' => '',
    'basePath' => APPLICATION_PATH)
);


$autoloader = Zend_Loader_Autoloader::getInstance(); //MAYBE NOT
$autoloader->setFallbackAutoloader(true);      //MAYBE NOT

return $moduleLoader;

Added:

given the answers, is it a good thing to do it this way? Is there overhead or开发者_JS百科 anything that's not good about it, or is this the standard practice?


The second line is kind of workaround for cases when standard structure autoloader is not enough, and should be avoided, because it slows things down (even if sometimes it is very handy).

Looks like the fallback autoloader will not be available in ZF 2.0.

  • Matthew Weier O'Phinney talks about "Autoloading Benchmarks"


It will cause the specified autoloader to be used for any namespace and classes that are not namespaced, effectively ignoring 'namespace' parameter if no autoloader for that namespace is defined.

It is appropriate to use $autoloader->setFallbackAutoloader(true) when you have classes that do not belong to a namespace, or you need to use classes across many different namespaces.


First line is trivial, second line is mentioned at the manual: It means, that the Zend Autoloader will try to (auto)load every class, not only the classes mentioned as prefix, or registered Autoloader.


The first is to get the instance of the autoloader, that is it. As the autoloader is a singleton it can only have one instance. If that instance doesn't exist yet, it will be created.

The second line is to have the autoloader act as a catch all - whenever something isn't found, the autoloader is triggered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜