探索,發現,愛好、學習,記錄,分享。
學海無涯,天涯若比鄰,三人行,必有我師。

在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()了。

版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權
轉載事宜:如需轉載需徵得應允,轉載必須注明來源於本站的信息。
文章名称:《在PHP7.2下使用Discuz發生 PHP Deprecated: __autoload() is deprecated 的解決方法》
文章链接:https://www.thefreesky.com/blog/25822.html
本站資源僅供個人學習交流,請於下載後24小時內刪除,不允許用於商業用途,否則法律問題自行承擔。

評論 抢沙发