报错: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的键值不存在而被使用了。
例如:
<br /><?php<br />$arr = array('a'=>123);<br /><span style="color:transparent">/本文来源gaodai#ma#com搞*!代#%^码网%</span><sub>搞代gaodaima码</sub>echo $arr['allowhtml']; // 这样就会有提示未定义了。<br />?><br />
——解决思路———————-
$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);
来补偿你的过失
——解决思路———————-
那是因为你的旧服务器设置了不输出notice,warning的错误,所以不显示。
你可以在程序顶加上
error_reporting(E_ALL^E_NOTICE^E_WARNING);
<br /><?php<br />error_reporting(E_ALL^E_NOTICE^E_WARNING); // 加了这句就可以屏蔽警告与提示的错误。<br />$arr = array('a'=>123);<br />echo $arr['allowhtml']; // 这里不会出现notice<br />?><br />