Why should we use spl_autoload_register to replace _ autoload ()? Besides multiple registrations, why should we use
spl_autoload_registerTo replace
__autoload()
Besides multiple registrations
Reply content:
Why?spl_autoload_registerTo replace__autoload()
Besides multiple registrations
If there must be multiple autoload functions,spl_autoload_register()Allows for this. It extends tively creates a queue of autoload functions, and runs through each of them in the order they are defined. By contrast,__autoload()May only be defined once.
spl_autoload_registerIt can well handle the situation where multiple loaders are needed. In this casespl_autoload_registerThe previously registered loaders are called sequentially. For comparison,__autoloadBecause it is a function, it can only be defined once.
This is a sentence in the English document.spl_autoload_registerBut it does not appear in the Chinese document.
Http://www.jb51.net/article/37746.htm
This is very detailed.
Spl_autoload_register
(PHP 5> = 5.1.2)
Spl_autoload_register-register _ autoload () function
Description
Bool spl_autoload_register ([callback $ autoload_function])
Register the function to the SPL _ autoload function stack. If the functions in the stack are not activated, activate them.
If the _ autoload function has been implemented in your program, it must be explicitly registered to the _ autoload stack. Because
The spl_autoload_register () function replaces the _ autoload function in Zend Engine with spl_autoload () or
Spl_autoload_call ().
Autoload_function
The registered automatic loading function. If no parameter is provided, the default function of autoload is automatically registered.
Spl_autoload ().
Description
If the call succeeds, TRUE is returned. If the call fails, FALSE is returned.
Note: SPL is the abbreviation of Standard PHP Library (Standard PHP Library. It is an extension library introduced by PHP5. Its main functions include the implementation of the autoload mechanism and various Iterator interfaces or classes. The implementation of the SPL autoload mechanism is achieved by pointing the function pointer autoload_func to the self-implemented function with the automatic loading function. SPL has two different functions: spl_autoload and spl_autoload_call. Different automatic loading mechanisms are implemented by pointing autoload_func to these two function addresses!