The first step is to set include_path, which is the address of the file when php calls include.
The following is require_once 'zend/Loader/Autoloader. php ';
In Zend/Loader/Autoloader. the PHP file reads Zend/Loader. php. This php defines the Zend_Loader class, which contains functions such as loadClass, loadFile, and isReadable (whether the file is readable ).
The process of instantiating Zend_Loader_Autoloader is to call its constructor (the Singleton mode is used here ).
In its constructor, spl_autoload_register (array (_ CLASS __, 'autoload'); uses Zend_Loader_Autoloader: autoload as the CLASS to automatically load the function.
An operation is also performed to assign _ internalAutoloader to its own _ autoload.
As for how to use autoload, we will refer to the specific example.
Next we call Zend_Loader_Autoloader: registerNamespace ("USVN _"), this function only mounts a value with the key USVN _ and value true on the internal attribute _ namespaces of Zend_Loader_AutoLoader.
When you see this function, you can understand that the code can also be written.
Now we have called the USVN_Config_Ini class.
This class naturally follows Zend_Loader_Autoloader: autoload ("USVN_Config_Ini ")
The first step of this function is to call getClassAutoloaders to obtain the AutoLoader of this class. GetClassAutoloaders adds the selection and determination of namespaceAutoloader. because we seldom use it, skip it directly.
It is actually the _ internalAutoloader set above.
Here, Zend_Loader_Autoloader: _ autoload ("USVN_Config_Ini") is actually called ")
Now we can see the Zend_Loader_Autoloader: _ autoload function.
$ Callback = $ this-> getDefaultAutoloader ();
The default Autoloader will be obtained here. what is the default Autoloader? The initial definition of this class is actually array ('zend _ loader', 'loadclass ');
The following calls call_user_func ($ callback, $ class); that is, Zend_Loader: loadClass ("USVN_Config_Ini ")
First, Zend_Loader has been require in AutoLoader. php.
Next, let's take a look at the Zend_Loader: loadClass method. The first step of this method is to check for exceptions and skip. The second step is to separate classes and piece them together into $ file, such as USVN/Config/Ini. php. the following calls self: loadFile ($ file, null, true) directly );
Next, check self: loadFile,
First, check whether the class name contains invalid characters. if not, include this $ file. The $ file here is of course a relative path and needs to be spliced with include_path. do you remember where include_path was set? Set it at the beginning of the program! Now, we will read the USVN_Config_Ini class.
If you have defined a class and registered a Namespace, such as USVN, then you should create a folder with the same name under include_path (case-sensitive), and then the relative file path name you want to introduce is read separately by class name.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.