報錯:Use of undefined constant allowhtml 與Undefined index
運行程式報如下錯誤,這是哪裡出問題了?
Notice: Use of undefined constant allowhtml - assumed 'allowhtml' in /home/wwwroot/kaimen360_com/public_html/uc_client/model/base.php on line 69
Notice: Undefined index: allowhtml in /home/wwwroot/kaimen360_com/public_html/uc_client/model/base.php on line 69
------解決思路----------------------
使用了未經定義(不存在)的關聯鍵
錯誤資訊已給出的出錯位置 /home/wwwroot/kaimen360_com/public_html/uc_client/model/base.php on line 69
麻煩你自己看一下
------解決思路----------------------
提示你,在數組中沒有那個鍵名(不存在)為 allowhtml 的資料
------解決思路----------------------
數組中allowhtml的索引值不存在而被使用了。
例如:
$arr = array('a'=>123);
echo $arr['allowhtml']; // 這樣就會有提示未定義了。
?>
------解決思路----------------------
$a = array();
echo $a[allowhtml];
關聯鍵名沒有用引號括起(不是字串),php 會先檢查是否為常量,由於沒有定義,所以有
Notice: Use of undefined constant allowhtml - assumed 'allowhtml' in ...
然後按字串檢查數組中是否有同名項,因為沒有,所以有
Notice: Undefined index: allowhtml in ...
這是因為你沒有書寫健壯的代碼造成的
php.ini 中預設 error_reporting = E_ALL
你可改為 error_reporting = E_ALL ^ E_NOTICE
或在程式開始處執行 error_reporting(E_ALL ^ E_NOTICE);
來補償你的過失
------解決思路----------------------
引用:
Quote: 引用:
數組中allowhtml的索引值不存在而被使用了。
例如:
$arr = array('a'=>123);
echo $arr['allowhtml']; // 這樣就會有提示未定義了。
?>
怎麼解決呀?
我遷移了伺服器就報這樣的錯誤,沒有遷移伺服器前好好的,這是為什嗎?
那是因為你的舊伺服器設定了不輸出notice,warning的錯誤,所以不顯示。
你可以在程式頂加上
error_reporting(E_ALL^E_NOTICE^E_WARNING);
error_reporting(E_ALL^E_NOTICE^E_WARNING); // 加了這句就可以屏蔽警告與提示的錯誤。
$arr = array('a'=>123);
echo $arr['allowhtml']; // 這裡不會出現notice
?>