Ecshop 執行報錯總結
多是因為版本高於5.3的問題
1、Strict Standards: Only variables should be passed by reference in 418
找到第418行
$tag_sel = array_shift(explode(' ', $tag));
PHP5.3以上預設只能傳遞具體的變數,而不能通過函式返回值傳遞,所以這段程式碼中的explode就得移出來重新賦值了。
替換為:
$tagArr = explode(' ', $tag);
$tag_sel = array_shift($tagArr);
2、Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 300
找到300行
return preg_replace("/{([^\}\{]*)}/e", "\$this->select('\\1');", $source);
替換為:
return preg_replace_callback("/{([^\}\{]*)}/", function($r) { return $this->select($r[1]); }, $source);
mobile中替換為:
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r [1]); }, $source);
3、Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 491
找到491行
$out = "<?php " . '$k = ' . preg_replace("/(\'\\$[^,] )/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";";
替換為:
$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($r) {return stripslashes(trim($r[1],'\''));}, var_export($t, true)) . ";\n";
4、Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 550
找到550行
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
替換為:
$val = preg_replace_callback('/\[([^\[\]]*)\]/is',function ($matches) {return '.'.str_replace('$','\$',$matches[1]);},$val);
5、Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 1074
找到1074行
$source = preg_replace($pattern, $replacement, $source);
替換為:
$source = preg_replace_callback($pattern, function ($matches) { return '{include file='.strtolower($matches[1]). '}';},$source);
同時,修改上面前兩行的
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
把最後的e去掉
6、Strict Standards: Redefining already defined constructor for class cod in /Applications/MAMP/htdocs/shoptest1/includes/modules/payment/cod.php on line 82
PHP 類,有兩種建構函式,一種是跟類同名的函式,一種是 ____construct()。從PHP5.4開始,對這兩個函數出現的順序做了最嚴格的定義,必須是 ____construct() 在前,同名函式在後。類似這種報錯都可以這樣解決,把____construct函式放到前面。