php5.6 ecshop,PHP 5.6以上版本运行 ecshop不兼容问题解决方案
在安裝完php在本地服務器上后, 發現在靜態網頁上出現了很多 error。
在查找相關資料過后發現,大部分問題是因為?PHP發展到PHP5.5版本以后,有了很多細微的變化。而ecshop官方更新又太慢,發現這些問題后也不及時升級,導致用戶安裝使用過程中出現BUG。
問題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);
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();
問題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
錯誤,別著急,先定位到出錯的文件,查找下是不是在程序中使用了”=&”,例如阿茲貓剛才定位到網站程序中發現了下圖的程序,發現使用了”=&
amp;”符號,去掉‘&’符號之后程序運行正常。
解決方法:
搜索所有PHP文件,將”=&”替換為”=”
問題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
出錯原因:
這個錯誤提示的意思:mktime()方法不帶參數被調用時,會被拋出一個報錯提示。PHP5.1版后調用mktime()不帶參數,會彈出這個違反標準的通知。如果要不帶參數調用mktime,等同于調用time(),應用其代替。
解決方法:
$auth = mktime();
將mktime()替換成time()方法,代碼為:
$auth = time();
問題6:
Strict Standards: Redefining already defined constructor for class cls_sql_dump ......
出錯原因:
原因跟PHP類中的構造函數有關,PHP早期版本是使用跟類同名的函數作為構造函數,后來又出現了使用 __construct()作為構造函數,
這倆個函數可以同時存在。到了PHP5.4版本,對這倆個函數在代碼中的先后順序有了嚴格的要求。在PHP5.4版本下,必須__construct() 在前,
同名函數在后,否則就會出現上面的的錯誤提示。
解決方法:
把__construct()函數放在,同名函數上面就行了。
問題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)
如出現類似錯誤,可以以同樣的方法解決。
問題8:
Strict Standards: Redefining already defined constructor for class paypal
出錯原因:
PHP 類,有兩種構造函數,一種是跟類同名的函數,一種是 ____construct()。從PHP5.4開始,對這兩個函數出現的順序做了最嚴格的定義,必須是 ____construct() 在前,同名函數在后
解決方法:
例如:
function __construct()
{
$this->paypal();
}
function
paypal()
{
}
問題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。
問題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)的上邊。
資料由優易ecshop整理,更多文章經登錄http://www.uuecs.com,轉載請注明
總結
以上是生活随笔為你收集整理的php5.6 ecshop,PHP 5.6以上版本运行 ecshop不兼容问题解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 72、【backtrader期货策略】十
- 下一篇: 浅析 - 阿里巴巴专家教你坚持写作