找回密码
 新建账号

PHP Deprecated: __autoload() is deprecated in PHP 7.2

[复制链接]
php 发表于 2017/11/29 13:26 | 显示全部楼层 |阅读模式
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,用文件编辑软件打开,搜索
    1. if(function_exists('spl_autoload_register')) {
    2.         spl_autoload_register(array('core', 'autoload'));
    3. } else {
    4.         function __autoload($class) {
    5.                 return core::autoload($class);
    6.         }
    7. }
    复制代码

  • 将else部分删除,代码变为
    1. if(function_exists('spl_autoload_register')) {
    2.         spl_autoload_register(array('core', 'autoload'));
    3. }
    复制代码

  • 其实这个if判断也是没有必要的,因为从PHP 5.1开始就已经支持spl_autoload_register()了。
  • 高版本PHP已经忽略__autoload()这个自动加载函数,PHP 7.3 __autoload()失效不会被自动调用。

手机版|轻松E站

GMT+8, 2024/4/20 11:09

快速回复 返回顶部 返回列表