安装emlog 5.3.1出现__autoload() is deprecated弃用函数提示

时间:2020-08-01   阅读:329

在emlog安装界面出现Deprecated已弃用函数提示,“Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in ..\include\lib\function.base.php on line 7”,这是由于服务器php使用的是php7,而__autoload()函数在php7版本已经被弃用,解决方法是使用低版本的php(如php5.5等),或者替换该函数。

解决方法

方法一:

使用php7以下版本,如php 5.4、php 5.5等

方法二:

进入提示的路径include\lib\function.base.php,编辑function.base.php文件,找到第7行代码,即__autoload()函数,函数代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
function __autoload($class) {$class = strtolower($class);if (file_exists(EMLOG_ROOT . '/include/model/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/model/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/lib/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/lib/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/controller/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/controller/' . $class . '.php');} else {
		emMsg($class . '加载失败。');}}

将其修改为以下代码

1
2
3
4
5
6
7
8
9
10
11
12
spl_autoload_register(function($class) {$class = strtolower($class);if (file_exists(EMLOG_ROOT . '/include/model/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/model/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/lib/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/lib/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/controller/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/controller/' . $class . '.php');} else {
		emMsg($class . '加载失败。');}});

1
2
3
4
5
6
7
8
9
10
11
12
13
function autoload($class) {$class = strtolower($class);if (file_exists(EMLOG_ROOT . '/include/model/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/model/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/lib/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/lib/' . $class . '.php');} elseif (file_exists(EMLOG_ROOT . '/include/controller/' . $class . '.php')) {require_once(EMLOG_ROOT . '/include/controller/' . $class . '.php');} else {
		emMsg($class . '加载失败。');}}spl_autoload_register('autoload');

上面代码二选一,保存文件后,重新打开安装界面,deprecated提示消失。

PS:上面两个代码的区别是:一个是匿名函数引入,一个是把函数封装,都可以使用。

Emlog 5.3.1目前并不支持php7+版本,后面博客吧会分享在php7下安装使用emlog 5.3.x版本的教程。


原文地址:https://www.boke8.net/emlog-deprecated-autoload.html


上一篇:emlog博客在线访问人数统计代码

下一篇:实现Emlog 5.3.1支持php 7安装使用

网友评论