错误:__ autoload()已过时,请改用spl_autoload_register() [英] Error: __autoload() is deprecated, use spl_autoload_register() instead

查看:62
本文介绍了错误:__ autoload()已过时,请改用spl_autoload_register()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实时服务器上遇到PHP错误.我相信这是一个版本问题.

I am facing a PHP error on live server. I believe it is a version issue.

下面包括该错误,该错误发生在config.php文件中:-

The error is included below and occurs in the config.php file:-

错误:不建议使用__autoload(),请改用spl_autoload_register().

config.php文件中的代码段

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 );
        }
    }
}

推荐答案

使用 spl_autoload_register 添加类加载器函数.

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);

这篇关于错误:__ autoload()已过时,请改用spl_autoload_register()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆