ecshop二次开发在PHP5.4以上高版本报错的解决方案集合
20170608更新
这个ECSHOP高版本出错的修改是在做项目开发过程中边做边修改出来的,基本上支持到5.6都没发现什么问题了,下图是我系统运行的PHP版本情况,由于系统原因,我没有安装php5.6,另外,在后面如果遇到有更新的与PHP版本有关的BUG,也会在这里更新,大家可以关注。
一、include/cls_template.php
1、找到
$tag_sel = array_shift(explode(' ', $tag));
改为
$tag_arr = explode(' ', $tag); $tag_sel = array_shift($tag_arr);
2、 找到
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
改为
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]);}, $source);
3、找到
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" ,"stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
改为
$out = <?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($r){return stripslashes(trim($r[1],'\''));}, var_export($t, true)) . ";\n";
4、找到
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
改为
$val = preg_replace_callback("/\[([^\[\]]*)\]/", function($r) {return '.'.str_replace('$','$',$r[1]);}, $val);
5,找到
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se'; $replacement = "'{include file='.strtolower('\\1'). '}'"; $source = preg_replace($pattern, $replacement, $source);
改为
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s'; $source = preg_replace_callback($pattern, function($r){return '{include file='.strtolower($r[1]). '}';}, $source);
6、类似这样的报错:
Deprecated: preg_replace(): The /e
modifier is deprecated, use preg_replace_callback instead in
D:\wyh\ecshop\includes\cls_template.php on line 300
(1)错误原因:preg_replace() 函数中用到的修饰符 /e 在 PHP5.5.x 中已经被弃用了。如果你的PHP版本恰好是PHP5.5.X,那你的ECSHOP肯定就会报类似这样的错误。
(2)解决办法:
A、将 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);
B、将 cls_template.php
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
改为
$out = <?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($r) {return stripslashes(trim($r[1],'\''));}, var_export($t, true)) . ";\n";
C、将cls_template.php
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
改为
$val = preg_replace_callback("/\[([^\[\]]*)\]/", function($r) {return '.'.str_replace('$','$',$r[1]);}, $val);
D、将cls_template.php
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se'; $replacement = "'{include file='.strtolower('\\1'). '}'"; $source = preg_replace($pattern, $replacement, $source);
改为
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s'; $source = preg_replace_callback($pattern, function($r){return '{include file='.strtolower($r[1]). '}';}, $source);
二、include/lib_base.php
1、找到
return cls_image::gd_version();
改为
$p = new cls_image(); return $p->gd_version();
2、找到
function gd_version()
改为
static function gd_version()
三、admin/shop_config.php和sms_url.php
找到
$auth = mktime();
改为
$auth = time();
四、上传LOGO和水印出现Strict Standards: Only variables should be passed by reference
后台admin/shop_config.php,将两处
$ext = array_pop(explode('.', $file['name']));
改为
$ext_tmp = explode('.', $file['name']); $ext = array_pop($ext_tmp);
五、数据库备份出现edefining already defined constructor for class cls_sql_dump\admin\includes\cls_sql_dump.php on line 90
将
function __construct(&$db, $max_size =0) { $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()
八、支付出错:Strict Standards: Redefining already defined constructor for class kuaiqian in /data/web/includes/modules/payment/kuaiqian.php on line 83 Strict Standards: Redefining already defined constructor for class cod in /data/web/includes/modules/payment/cod.php on line 82
解决办法,将所有的构造函数放到前面,如alipay.php
将
function __construct() { $this->alipay(); }
移到
function alipay() { }
前面
九、出现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()