Tag Archives: __autoload()

How to Solve __autoload() does not execute error

After PHP5, there is an automatic loading mechanism for classes, which can be defined__Autoload function, when an undefined class is used, an error will occur when executing PHP, but at this time, the PHP engine will check whether there is a definition before returning the failure__Autoload to load the required classes

Recently, the project has been switched to php7.0, and an error message “deprecated:__autoload() is deprecated, use spl_autoload_register() instead in**********”

Cause php7 above versions do not support using “function”__Autoload() {} “, this error will be reported

Solution

1. Just lower the PHP version a little, both 5.6 and 5.4

2. Will__Autoload is rewritten to spl_autoload_Register mode loading (recommended)

//Old
function __autoload($name) {

}
//Modified
spl_autoload_register(function ($name) {

});

The content of the function body remains unchanged. So far, the problem has been solved