出錯:Use of undefined constant allowhtml 與Undefined index

來源:互聯網
上載者:User
報錯: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
?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.