在PHP7.2下使用Discuz發生 PHP Deprecated: __autoload() is deprecated 的解決方法

Discuz! PHP Deprecated:  __autoload() is deprecated, use spl_autoload_register() instead in source\class\class_core.php on line 27

PHP 7.2开始不主张使用function __autoload(){}来自动加载类文件。

__autoload() been DEPRECATED as of PHP 7.2.0. Relying on this feature is highly discouraged.

请使用spl_autoload_register($callable)来替代__autoload()自动加载函数。其中参数$callable是一个自定义函数。自定义函数的参数为需要加载的类。其他用法和使用__autoload()自动加载函数一样。
spl_autoload_register()可以注册多个自动加载函数,而使用自动加载函数__autoload()自动加载类时只能写一个__autoload()函数。

Discuz!使用传统的__autoload()来自动加载类文件,在PHP 7.2中运行需要改为spl_autoload_register()。

找到文件source\class\class_core.php,用文件编辑软件打开,搜

if(function_exists('spl_autoload_register')) {
        spl_autoload_register(array('core', 'autoload'));
} else {
        function __autoload($class) {
                return core::autoload($class);
        }
}

将else部分删除,代码变为

if(function_exists('spl_autoload_register')) {
        spl_autoload_register(array('core', 'autoload'));
}

其实这个if判断也是没有必要的,因为从PHP 5.1开始就已经支持spl_autoload_register()了。

給TA打賞
共{{data.count}}人
人已打賞
網站源碼

DZ论坛SQL:SELECT value FROM [Table]vars WHERE name=\'noteexists1\'错误的解决方法

2018-6-26 22:14:49

網站源碼

修复人人商城更新至3.0.X后,分销商推广二维码不能生成。

2018-11-8 12:50:02

0 Reply AAuthor MManager
    暫無討論,說說你的看法吧
個人中心
購物車
優惠劵
今日簽到
有新私信 私信列表
搜索