PHP spl_autoload_register () function

Source: Internet
Author: User

Usage of Spl_autoload_register ():

Where $this represents the current class, AutoLoad () is my registered auto-load function, of course, this is just a function name, as long as it does not duplicate the PHP keyword, according to the general function name of the naming convention.

With automatic loading, when we need to load many other class files in a class, we don't have to use the Require () function frequently, so that the code looks more canonical and there is a significant improvement in performance that requires a look at the PHP kernel.

PHP relies on the Zend Engine parser, the Spl__autoload stack exists in the Zend engine, and when you use Spl_autoload_register () to register a function as an auto-load function, the function in the stack is activated. Even if the function name used in your program is __autoload (the method with __ in PHP is the Magic method), it must also be registered with the __autoload stack using the Spl_autoload_register () function display. Because Spl_autoload_register () replaces the __autoload function in Zend engine with spl_autoload () or Spl_autoload_call (). Whenever you instantiate a nonexistent class, SPL autoload by pointing the function pointer autoload_func to the function you implemented with the auto-mount function. SPL has two different function spl_autoload, Spl_autoload_call, to implement different automatic loading mechanisms by pointing autoload_func to these two different function addresses. Will trigger this function to load the corresponding class file, so as to achieve an ' automation ' effect, the world is in the pursuit of automation, the program is no exception.

PHP spl_autoload_register () function

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.