• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

出错:Use of undefined constant allowhtml 与Undefined index

php 搞代码 3年前 (2022-01-24) 14次浏览 已收录 0个评论

报错: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);
来补偿你的过失

——解决思路———————-

引用:
Quote: 引用:

数组中allowhtml的键值不存在而被使用了。
例如:

<br /><?php<br />$arr = array('a'=>123);<br />echo $arr['allowhtml'];  // 这样就会有提示未定义了。<br />?><br />

怎么解决呀?
我迁移了服务器就报这样的错误,没有迁移服务器前好好的,这是为什么?

那是因为你的旧服务器设置了不输出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 />

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:出错:Use of undefined constant allowhtml 与Undefined index

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址