PHP 5.6.6 上运行 ecshop 2.7.3 不兼容问题整合

在安装完php在自己的服务器上以后, 发现在静态网页上出现了很多 error。

在网上查找过后发现,大部分问题是因为 PHP发展到PHP5.5版本以后,有了很多细微的变化。而ECSHOP官方更新又太慢,发现这些问题后也不及时升级,导致用户安装使用过程中错误百出。

在这里我整理一下我遇到的问题希望对你们能有些帮组也为了自己以后查看。

问题1:

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in cls_template.php XXX line

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \upload\includes\cls_template.php on line 300

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \upload\includes\cls_template.php on line 557

出错原因:

出现以上问题是 preg_replace() 函数中用到的修饰符 /e 在 PHP5.5.x 中已经被弃用了。在PHP 5.5以上的版本用 preg_replace_callback 函数替换了 preg_replace函数。

解决方法:

解决问题的方法就是将代码中使用 preg_replace 函数的部分全部替换成 preg_replace_callback 函数,并且将一被废弃的 /e 修饰符 删除。

例子: 

return preg_replace("/{([^\}\{\n]*)}/e", "\$this->sel ect('\\1');", $source);

替换为

return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->sel ect($r[1]); }, $source);

参考文献:

http://www.68ecshop.com/article-1193.html

preg_replace 函数介绍 http://php.net/manual/zh/function.preg-replace.php

preg_replace_callback 函数介绍 http://php.net/manual/zh/function.preg-replace-callback.php

问题2:

Strict Standards: Only variables should be passed by reference in ......\includes\cls_template.php on line 418

Strict Standards: Only variables should be passed by reference in D:\xampp\htdocs\ECShop\upload\includes\cls_template.php on line 424

出错原因:

出现这个问题的原因,貌似在php5.4中array_shift只能为变量,不能是函数返回值。

中文意思为:“传入的变量只能为引用变量”。array_shift这个函数的参数是引用传递的,php5.3以上默认只能传递具体的变量,而不能通过函数返回值来传递。

解决方法:

$tag_sel = array_shift(explode(‘ ‘, $tag));

替换成

$tag_arr = explode(‘ ‘, $tag);
$tag_sel = array_shift($tag_arr);

然后删除工程目录下的temp文件夹,重新拷贝一份原始的temp文件夹进来,再访问首页,就会发现一切正常了!

问题3: 

Strict Standards: Non-static method cls_image::gd_version() should
not be called statically in ......\includes\lib_base.php on line 346  
或者

Strict Standards: Non-static method cls_image::gd_version() should
not be called statically in ......\includes\lib_installer.php on line
31

Strict Standards: Non-static method cls_image::gd_version() should not be called statically in \upload\includes\lib_base.php on line 346

出错原因:

如问题中提示的一样,因为 cls_image.php 中 gd_version() 不是 static 函数所以在lib_base.php 与 lib_installer.php 中调用时才会出现以上问题。

解决方法:

解决方法1:    首先在 lib_image.php 文件中,用 Shift+F 去搜索 gd_version 函数。然后在gd_version 方法前加 static 修饰符,是此函数变成静态函数。

解决方法2:    在lib_base.php 与 lib_installer.php 函数中找到
cls_image::gd_version() 部分, 然后分别创建cls_image 实例,之后用创建的实例再去调用 gd_version()
函数。

$cls_gile = new cls_image();

return $cls_gile->gd_version();

参考文献:

http://www.ecshop120.com/ecshop-ercikaifa/article-275.html

问题4:

Deprecated: Assigning the return value of new by reference is deprecated in…

Deprecated: Assigning the return value of new by reference is deprecated in  \admin\sitemap.php on line 46

出错原因:

PHP5.3+废除了”=&”符号,对象复制用”=”

在5.3版本之后已经不允许在程序中使用”=&”符号。如果你的网站出现了Deprecated: Assigning the return value of new by reference is deprecated in 错误,别着急,先定位到出错的文件,查找下是不是在程序中使用了”=&”,例如阿兹猫刚才定位到网站程序中发现了下图的程序,发现使用了”=&”符号,去掉‘&’符号之后程序运行正常。

解决方法:

搜索所有PHP文件,将”=&”替换为”=”

参考文献:

http://www.111cn.net/wy/CMS/62949.htm

http://www.phpally.com/ecshop%E6%8A%A5%E9%94%99deprecated-assigning-the-return-value-of-%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/comment-page-1/

问题5:

Strict Standards: mktime(): You should be using the time() function instead in ......\admin\shop_config.php on line 32(后台商店设置)

Strict Standards: mktime(): You should be using the time() function instead in \upload\admin\shop_config.php on line 32

Strict Standards: mktime(): You should be using the time() function instead in \upload\admin\sms_url.php on line 31

参考资料:

http://www.wuwenhui.cn/3268.html

出错原因:

这个错误提示的意思:mktime()方法不带参数被调用时,会被抛出一个报错提示。PHP5.1版后调用mktime()不带参数,会弹出这个违反标准的通知。如果要不带参数调用mktime,等同于调用time(),应用其代替。

解决方法:

$auth = mktime();

将mktime()替换成time()方法,代码为:

$auth = time();

参考文献:

http://www.weste.net/2014/6-18/97356.html

问题6:

Strict Standards: Redefining already defined constructor for class cls_sql_dump ......

出错原因:

原因跟PHP类中的构造函数有关,PHP早期版本是使用跟类同名的函数作为构造函数,后来又出现了使用 __construct()作为构造函数,

这俩个函数可以同时存在。到了PHP5.4版本,对这俩个函数在代码中的先后顺序有了严格的要求。在PHP5.4版本下,必须__construct() 在前,

同名函数在后,否则就会出现上面的的错误提示。

解决方法:

把__construct()函数放在,同名函数上面就行了。

参考文献:

http://www.ecshop120.com/ecshop-ercikaifa/article-253.html

问题7:

Strict Standards: Declaration of vbb::set_cookie() should be
compatible with integrate::set_cookie($username = '', $remember = NULL)

\includes\modules\integrates\ucenter.php......

子类的方法名如果和父类方法名相同,则子类的参数列表也要和父类的参数列相同。

出错问题:

vbb继承了integrate类并且重写了 set_cookie() 函数,但vbb重写set_cookie函数的参数 与 其父类set_cookie 的参数不符所以出现以上问题。

子类的函数跟父类的同名,必须使子类的函数参数跟父类的对应函数参数个数相同
依据错误提示,修改例如:

解决方法:

function set_cookie ($username="")
改为
function set_cookie ($username="", $remember = NULL)

如出现类似错误,可以以同样的方法解决。

参考文献:

http://blog.sina.com.cn/s/blog_6f145be10102v2px.html

问题8:

Strict Standards: Redefining already defined constructor for class paypal

出错原因:

PHP 类,有两种构造函数,一种是跟类同名的函数,一种是 ____construct()。从PHP5.4开始,对这两个函数出现的顺序做了最严格的定义,必须是 ____construct() 在前,同名函数在后

解决方法:

例如:
function __construct()

{

       
$this->paypal();
    }
   
    function
paypal()
    {
    }
参考资料:http://blog.sina.com.cn/s/blog_6f145be10102v2px.html
 
问题9:
ecshop2.7.3 gbk版在php5.4下安装后,分类名称文字不显示问题

htmlspecialchars()从 php5.4.0 版本开始第三个参数字符串编码的默认值改成了 UTF-8,而ecshop2.7.3
gbk版的中文编码是 GB2312 编码的,跟现在的默认参数不一致,导致所有htmlspecialchars()处理的字符都无法显示。
解决办法:
$str_converted = htmlspecialchars($str, ENT_COMPAT ,'GB2312');
建议php5.4下不要安装gbk编码ecshop。

参考资料:http://www.111cn.net/wy/CMS/62949.htm

问题10:

网站后台验证码不显示PHP Strict Standards:  Redefining already defined constructor for class captcha in D:\web\322\includes\cls_captcha.php on line 119

打开 includes/cls_captcha.php

 
找到下面这段代码
   function __construct($folder = '', $width = 145, $height = 20)
    {
        $this->captcha($folder, $width, $height);
    }
将它移到
function captcha($folder = '', $width = 145, $height = 20)的上边。

转载:

http://www.cnblogs.com/AlvinLiang/p/4228223.html

http://www.cnblogs.com/Gile/p/4333887.html

上一篇:elk 架构


下一篇:Zabbix 监控rabbitmq