尝试使用数组偏移量访问空类型值
P粉334721359
P粉334721359 2023-08-25 09:40:08
[PHP讨论组]
<p>我有一个php机器人(在IRC上),自从我将php和mysql更新到CentOS的最新版本后,我遇到了这个错误</p> <pre class="brush:php;toolbar:false;">unset($ops_activos); unset($voices_activos); if ($on_pthelp == 1) { if ($ops[&quot;#pthelp&quot;]['count'] &gt; 0) { foreach ($ops[&quot;#pthelp&quot;] as $value) { if (!is_int($value)) { if (isset($ops_activos)) { $ops_activos .= &quot; &quot; . $value; } else { $ops_activos = $value; } } } if ($bot_debug) { scmd(&quot;PRIVMSG &quot;. $log_chan .&quot; :[Membros (Mode)] [OPS]: &quot;. $ops_activos); } } unset ($value); if ($voices[&quot;#pthelp&quot;]['count'] &gt; 0) { foreach ($voices[&quot;#pthelp&quot;] as $value) { if (!is_int($value)) { if (isset($voices_activos)) { $voices_activos .= &quot; &quot; . $value; } else { $voices_activos = $value; } } } if ($bot_debug) { scmd(&quot;PRIVMSG &quot;. $log_chan .&quot; :[Membros (Mode)] [VOICES]: &quot;. $voices_activos); } }</pre> <p>错误所在行</p> <pre class="brush:php;toolbar:false;">if ($ops[&quot;#pthelp&quot;]['count'] &gt; 0) {</pre></p>
P粉334721359
P粉334721359

全部回复(1)
P粉268654873

在比较之前,您需要检查数组中是否存在您拥有的键,因为无论如何它都找不到它。

请改用以下代码:

if (isset($ops["#pthelp"]['count']) && $ops["#pthelp"]['count']> 0)

此外,这样做可以避免任何进一步的问题。

if (isset($voices["#pthelp"]['count']) &&  $voices["#pthelp"]['count'] > 0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号