PHP function __autoload failure reason (related to Smarty)

Source: Internet
Author: User
PHP function __autoload can implement simple automatic loading, but after the introduction of Smarty found that the __autoload function is invalid, and later found to be the reason for the Spl_autoload_register function.

Execute the following code:

function __autoload ($name) {require ' class/'. $name. PHP '; Echo ' 1 ';} function Autoload_test ($name) {echo ' 2 ';} Spl_autoload_register (' autoload_test '); $ca =new CA ();

Output 2, you can see that the __autoload function is not executed, the official website of the resolution is: if you have implemented the __autoload () function in your program, it must be explicitly registered in the __autoload () queue. Because the Spl_autoload_register () function replaces the __autoload () function in Zend Engine with spl_autoload () or Spl_autoload_call ().

In order for the code to work properly, you should reregister the __autoload function:

function __autoload ($name) {require ' class/'. $name. PHP '; Echo ' 1 ';} function Autoload_test ($name) {echo ' 2 ';} Spl_autoload_register (' autoload_test '); Spl_autoload_register (' __autoload '); $ca =new CA ();

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP function __autoload failure reason (related to smarty), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.