问题
I am facing a PHP error on live server. I believe it is a version issue.
The error is included below and occurs in the config.php file:-
ERROR: __autoload() is deprecated, use spl_autoload_register() instead.
Code snippet from config.php file
if (!function_exists('__autoload')) {
function __autoload($class) {
if (strpos($class, 'Auth_Controller') === 0) {
@include_once( APPPATH . 'core/' . $class . EXT );
}
if (strpos($class, 'Rest_Controller') === 0) {
@include_once( APPPATH . 'core/' . $class . EXT );
}
}
}
回答1:
Use spl_autoload_register
to add a class loader function.
It is also a good practice to end the function just after finding the class.
$autoload = function ($class) {
if (strpos($class, 'Auth_Controller') === 0) {
@include_once( APPPATH . 'core/' . $class . EXT );
return;
}
if (strpos($class, 'Rest_Controller') === 0) {
@include_once( APPPATH . 'core/' . $class . EXT );
return;
}
};
spl_autoload_register($autoload);
来源:https://stackoverflow.com/questions/59045274/error-autoload-is-deprecated-use-spl-autoload-register-instead