Ecshop高版本PHP兼容性问题概述
Ecshop未能及时适配新版本,若在较高版本的PHP虚拟主机上部署该程序,将引发兼容性问题。
笔者在本地PHP 5.5环境中安装时,遇到了两类典型的报错信息。
第一类为“Only variables should be passed by reference”;第二类为“Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead”。
经网络检索发现,Ecshop并非仅能在低版本PHP中运行,目前已找到相应的解决方案,旨在协助大家在PHP 5.5版本下顺利调试程序,现将方法分享如下。
首先说明第一个问题的处理办法:
这是PHP 5.3以上版本因配置差异导致的问题,只需将第418行的代码拆分为两句即可解决。
原始代码如下:
$tag_sel = array_shift(explode(' ', $tag));
需修改为:
$tag_arr = explode(' ', $tag); $tag_sel = array_shift($tag_arr);
原因在于array_shift的参数采用引用传递,而在PHP 5.3及以上版本中,默认只能传递具体变量,不支持直接传递函数返回值。
第二个报错的处理方法如下:
定位到文件:include/cls_template.php
找到以下代码段:
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
将其替换为:
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);
笔者目前仅遇到上述两个报错,若在后续程序调试和开发过程中遇到其他问题且能解决,将继续整理相关解决方法。
Ecshop在高版本PHP下常见报错及解决汇总
1. Ecshop提示Strict Standards: Non-static method cls_image
::gd_version() should not be called statically inE:/wwwroot/weirenchou/includes/lib_base.php on line 346
定位到第346行
return cls_image::gd_version()
替换为:
$p = new cls_image();return $p->gd_version();
2. Ecshop运行时出现如下错误:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /ecshop/includes/cls_template.php on line 300
打开Ecshop目录,找到includes/cls_template.php文件,定位至第300行
将
return preg_replace("/{([^/}/{/n]*)}/e", "/$this->select('//1');", $source);
替换为
return preg_replace_callback("/{([^/}/{/n]*)}/", function($r) { return $this->select($r[1]); }, $source);
3. Strict Standards: Only variables should be passed by reference in E:/web/shopex/includes/cls_template.php on line 422
$tag_sel = array_shift(explode(' ', $tag));
改为:
$tag_arr = explode(' ', $tag); $tag_sel = array_shift($tag_arr);
4. 会员整合时出现
phpbb::set_cookie() should be compatible with integrate
/includes/modules/integrates/phpbb.php on line 232
110行
function set_cookie ($username="")
修改为
function set_cookie ($username="", $remember = NULL)
includes/modules/integrates/phpwind6.php
ucenter.php与vbb.php也需进行相同修改
ucenter.php第210行修改为
function add_user($username, $password, $email, $gender = -1, $bday = 0, $reg_date = 0, $md5password = '')
第127行修改为
function login($username, $password, $remember = NULL)
5. 数据库备份时出现
edefining already defined constructor for class cls_sql_dump
/admin/includes/cls_sql_dump.php on line
function __construct(&$db, $max_size =)
{
$this->cls_sql_dump($db, $max_size);
}
移至function cls_sql_dump(&$db, $max_size=0)之前
Non-static method cls_sql_dump::get_random_name() admin/database.php on line 64
打开includes/cls_sql_dump.php
第479行
function get_random_name()
修改为
static function get_random_name()