PHP function __autoload can achieve simple automatic loading, but after introducing smarty, it was found that the __autoload function was invalid. Later, it was found that the reason was 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();
In order for the code to work properly, the __autoload function should be re-registered:
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 Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the reasons for the failure of PHP function __autoload (related to smarty), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.