简体   繁体   English

正在注册所需的自动加载器zend_loader :: registerAutoload()

[英]Is registering the autoloader needed zend_loader::registerAutoload()

I'm guessing this line registers the autoload function, which in turn loads needed Zend classes. 我猜这行注册了自动加载功能,该功能反过来加载所需的Zend类。

Zend_Loader::registerAutoload();

My question: is this line meant to be used in applications that call some zend components but aren't fully zend applications? 我的问题:这条线是否打算在调用某些zend组件但不是完全zend应用程序的应用程序中使用? or is needed also in applications that are fully zend and use zend MVC? 还是在完全zend并使用zend MVC的应用程序中还需要?

Well, first we should note that Zend_Loader::registerAutload() is deprecated (since 1.8.0). 好吧,首先我们要注意Zend_Loader::registerAutload()已被弃用(自1.8.0开始)。 Better is: 更好的是:

Zend_Loader_Autoload::getInstance();

What this does is register an SPL __autoload($classname) function that attempts load classes when they are called for but not-yet-loaded. 这是注册一个SPL __autoload($classname)函数,该函数在被调用但尚未加载时尝试加载类。 The default behavior of this autoloader in a non-framework application is to map a class name to a file name (relative to the currently defined include_path ) and include() that file in the hopes that the requested class will be defined there. 在非框架应用程序中,此自动加载器的默认行为是将类名映射到文件名(相对于当前定义的include_path ),并对该文件进行include() ,以希望在此处定义所请求的类。

The specific mapping uses the PEAR 1-class-1-file convention in which a class named something like My_ComponentName_ClassName will reside in the file My/ComponentName/ClassName.php . 特定的映射使用PEAR 1-class-1-file约定 ,其中一个名为My_ComponentName_ClassName类的类将驻留在文件My/ComponentName/ClassName.php

See this answer for more details. 有关详细信息,请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM