
ecshop是国内比较流行的搭建网上商城的开源php软件,但其更新较慢,只能在PHP5.2/5.3正常运行。而现在php版本已经更新到7.0了,使用php5.2/5.3的人越来越少,更多的人转向使用更高的php版本。可以通过修改部分ecshop代码让其支持PHP5.5及以上版本。
1、Deprecated: Assigning the return value of new by reference is deprecated in F:\xampp\htdocs\ecsphp5\includes\lib.debug.php on line 303
- $pa = &new Print_a_class;
- //修改为:
- $pa = new Print_a_class;
PHP5.3+废除了”=&”符号,对象复制用”=”即可,详细如下:
PHP5对象复制是采用引用的方式。
如果不采用引用方式,则需要在复制对象时加关键字 clone。
如果在复制的过程中,同时要变更某些属性,则增加函数_clone()。
2、Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead *
出现这个错误的原因是 preg_replace() 函数修饰符 /e 在 PHP5.5.x 中已经被弃用了,若出现这个错误可以用 preg_replace_callback 进行代替。(一般的可以直接去掉 e 函数,但以下需要用preg_replace_callback代替)
2.1 \includes\cls_template.php 文件中的 fetch_str()函数
- return preg_replace("/{([^\}\{\n]*)}/", "\$this->select('\\1');", $source);
- //修改为
- return preg_replace_callback("/{([^\}\{\n]*)}/",
- function ($match){
- return $this->select($match[1]);
- }, $source);
2.2 \includes\cls_template.php 文件中的 smarty_prefilter_preCompile()函数
- $replacement = "'{include file='.strtolower('\\1').}'";
- $source = preg_replace_callback($pattern, $replacement, $source);
- //修改为
- $source = preg_replace_callback($pattern, function($match){
- return '{include file="'.strtolower($match[1]).'"}';
- }, $source);
2.3 \includes\cls_template.php 文件中的 get_val()函数
- $val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
- //修改为
- $val = preg_replace_callback("/\[([^\[\]]*)\]/is",function($match){
- return ".".str_replace('$','\$',$match[1]);
- }, $val);
2.4 \includes\cls_template.php 文件中的 select()函数
- //$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
- //修改为
- $out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($match){
- return stripslashes(trim($match[1],'\''));
- }, var_export($t, true)) . ";\n";
3、 Strict Standards: Only variables should be passed by reference in *
5.3以上默认只能传递具体的变量,而不能通过函数返回值。可做类似以下修改;
- //\includes\lib_main.php
- $ext = end(explode('.', $tmp));
- //修改为
- $ext_arr = explode('.', $tmp);
- $ext = end($ext_arr);
- //includes\cls_template.php on line 422
- $tag_sel = array_shift(explode(' ', $tag));
- //修改为
- $tag_arr = explode(' ', $tag);
- $tag_sel = array_shift($tag_arr);
4、Strict Standards: Non-static method cls_image::gd_version() should not be called statically
- //修改 cls_image 类
- function gd_version()
- //修改为
- static function gd_version()
5 Strict Standards: mktime(): You should be using the time() function instead
直接用time 代替mktime即可。
PHP5.1版后调用mktime()不带参数,等同于调用time(),,应用其代替。
6 Strict Standards: Redefining already defined constructor for class
将同名构造函数 放在 __construct() 之后。
PHP类,有两种构造函数,一种是跟类同名的函数,一种是 __construct()。从PHP5.4开始,对这两个函数出现的顺序做了最严格的定义,必须是 __construct() 在前,同名函数在后。
涉及到的修改文件有
文件名文件大小最后修改时间状态
admin/
被修改: 5
cloud.php“8167 Bytes”2016/2/3 20:56被修改
privilege.php“25918 Bytes”2014/12/12 11:14被修改
shop_config.php“13702 Bytes”2016/2/3 20:56被修改
sms_url.php“1186 Bytes”2016/2/3 20:56被修改
sql.php“4634 Bytes”2014/12/12 11:19被修改
admin/includes/
被修改: 1
cls_sql_dump.php“14094 Bytes”2016/2/6 18:39被修改
includes/
被修改: 6
cls_captcha.php“8734 Bytes”2016/2/3 20:59被修改
cls_image.php“23083 Bytes”2016/2/2 23:10被修改
cls_mysql.php“27347 Bytes”2016/2/6 18:40被修改
cls_template.php“44542 Bytes”2016/2/6 19:49被修改
lib.debug.php“25893 Bytes”2016/2/2 21:59被修改
lib_main.php“67400 Bytes”2016/2/2 22:52被修改
includes/modules/payment/
被修改: 15
alipay.php“6661 Bytes”2016/2/6 18:10被修改
balance.php“2146 Bytes”2016/2/6 18:10被修改
bank.php“2091 Bytes”2016/2/6 18:10被修改
cappay.php“12133 Bytes”2016/2/6 18:10被修改
chinabank.php“5521 Bytes”2016/2/6 18:10被修改
cod.php“2208 Bytes”2016/2/6 18:10被修改
epay.php“5708 Bytes”2016/2/6 18:10被修改
ips.php“5554 Bytes”2016/2/6 18:11被修改
kuaiqian.php“13153 Bytes”2016/2/6 18:11被修改
paypal.php“8200 Bytes”2016/2/6 18:11被修改
paypal_ec.php“8429 Bytes”2016/2/6 18:11被修改
post.php“2134 Bytes”2016/2/6 18:11被修改
shenzhou.php“15209 Bytes”2016/2/6 18:11被修改
tenpay.php“8425 Bytes”2016/2/6 18:12被修改
tenpayc2c.php“8679 Bytes”2016/2/6 18:12被修改
修改后
后台
<img alt="ecshop 修改 兼容PHP5.5" src="https://s.yunzhuji.shop/uploads/image/160206/1l291nxr74.JPG_.jpg?media_id=319" title="ecshop 修改 兼容PHP5.5" width="600" >