解决安装ECshop时PHP版本大于5.2时的问题

随着PHP5.5 的普及,ECSHOP系统又爆出了新的错误。PHP发展到PHP5.5版本以后,有了很多细微的变化。而ECSHOP官方更新又太慢,发现这些问题后也不及时升级,导致用户安装使用过程中错误百出。

1.
说了半天,这个新错误到底是什么呢,它的完整错误提示信息是这样的:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in.......
注意:不是所有人的ECSHOP都会报这个错误,只有使用PHP5.5环境的ECSHOP才会报这个错误。
下面 ecshop模板网 教程先来说一下错误产生的原因:

错误原因:
preg_replace() 函数中用到的修饰符 /e 在 PHP5.5.x 中已经被弃用了。
如果你的PHP版本恰好是PHP5.5.X,那你的ECSHOP肯定就会报类似下面这样的错误:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in......

解决办法:
其实从刚才的错误提示信息中我们也能看出一二,它提示我们使用 preg_replace_callback 来代替 preg_replace。
所以解决方法如下:

使用记事本或其他PHP编辑软件(如:editplus)打开文件 includes/cls_template.php ,找到

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

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

如果你的ECSHOP中其他文件也报类似的 preg_replace错误,请参照上面方法解决之,解决思路和解决方法是一样的。
第491行
原有内容:
//$out = "<?php 
" . '$k = ' . preg_replace("/(\'\\$[^,] )/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";
";
修改后内容:
$out = "<?php 
" . '$k = ' . preg_replace_callback("/(\'\\$[^,] )/" , 
function($match){return stripslashes(trim($match[1],'\''));}
, var_export($t, true)) . ";
";

第1080行
原有内容:
//$source = preg_replace($pattern, $replacement, $source);
修改后内容:
$source = preg_replace_callback($pattern, 
function ($matches) { return '{include file='.strtolower($matches[1]). '}';},
$source);

2.
Strict Standards : Only variables should be passed by reference in  /sites/upload/includes/cls_template.php  on line  423
423             /*$tag_sel = array_shift(explode(' ', $tag));*/
424             $tag_tmp = (explode(' ', $tag));
425             $tag_sel = array_shift($tag_tmp);

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

  解决:找到install/includes/lib_installer.php中的第31行   return cls_image::gd_version();然后在找到include/cls_image.php中的678行,发现gd_version()方法未声明静态static,所以会出错。这时候只要:

  1)将function gd_version()改成static function gd_version()即可。

  2)或者将install/includes/lib_installer.php中的第31行return cls_image::gd_version();改成:

$p =  new  cls_image();
return  $p->gd_version();
Strict Standards : Only variables should be passed by reference in  /sites/upload/includes/lib_main.php on line 1329
    //$ext = end(explode('.', $tmp)); 
    $var_tmp = explode('.', $tmp);
    $ext = end($var_tmp);

猜你喜欢

转载自blog.csdn.net/yuexiaxiaoxi27172319/article/details/50749744