Why use Spl_autoload_register to replace __autoload ()

Source: Internet
Author: User
Why do you use spl_autoload_registerTo replace __autoload()
In addition to being able to register more than

Reply content:

Why use it spl_autoload_register to replace__autoload()
In addition to being able to register more than

If There must is multiple autoload functions, spl_autoload_register() allows for this. It effectively creates a queue of autoload functions, and runs through each of the them in the order they is defined. By contrast, May is __autoload() defined once.

spl_autoload_registerIt is good to handle situations where multiple loaders are required, in which case spl_autoload_register the previously registered loader is called sequentially. As a comparison, __autoload because it is a function, it can only be defined once.

This is a sentence in the English document explaining the meaning of the addition spl_autoload_register , but it seems not in the Chinese document.

Http://www.jb51.net/article/37746.htm
It's very detailed here.

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 in the SPL __autoload function stack. If the functions in the stack have not been activated, they are activated.
If you have implemented the __autoload function in your program, it must be explicitly registered in the __autoload stack. Because
The Spl_autoload_register () function replaces the __autoload function in Zend engine with the spl_autoload () or
Spl_autoload_call ().

Autoload_function
Registers the automatic load function. If no arguments are provided, the default implementation function for AutoLoad is automatically registered
Spl_autoload ().
Description
Returns TRUE if successful, and FALSE if it fails.
Note: SPL is the abbreviation for standard PHP library (PHP libraries). It is an extension library introduced by PHP5, whose main functions include the implementation of the AutoLoad mechanism and the inclusion of various iterator interfaces or classes. The implementation of the SPL autoload mechanism is achieved by pointing the function pointer autoload_func to its own implementation of the function that has the automatic loading function. SPL has two different function spl_autoload, Spl_autoload_call, by the Autoload_func point to these two different function addresses to implement different automatic loading mechanism!

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.