繁体   English   中英

越来越令人讨厌的错误:“致命错误:无法在…中使用字符串偏移量作为数组”

[英]getting really annoying error: “Fatal error: Cannot use string offset as an array in…”

我如何摆脱这个错误?

码:

        function get_green_entities($c,$array){
            $thisC = &$this->output[$this->sessID];    
            $timeDif = 4;
            $cols = count($thisC['clientCols'])+1;
            if(!isset($array['Entity ID'])){
                return get_grey($c);
            }
            if(!isset($thisC['CURRTIME'][$array['Entity ID']])){
                $thisC['CURRTIME'][$array['Entity ID']] = 
                      (isset($array['timestamp'])?$array['timestamp']:null);
            }
        }

我在最后一个if语句行中遇到该错误:

$thisC['CURRTIME'][$array['Entity ID']] = 
                          (isset($array['timestamp'])?$array['timestamp']:null);

而且我知道$array['Entity ID']=4

我该如何解决?

谢谢 :-)

更新3
我删除了转储,因为它们有点敏感

只有三种可能性: $thisC$thisC['CURRTIME']$array不是数组...

您可以更改功能签名以防止后者:

function get_green_entities($c, array $array)

如果$array是问题,则在调用该函数时将触发它。 因此,如果问题仍然存在,您现在知道它与$thisC

在错误发生之前在行上调用var_dump可以使问题很明显。

考虑以下行为:

$array = 'test';

if (!isset($array['foo']['bar']))
  $array['foo']['bar'] = true; // error is triggered here

因此,我认为问题在于$thisC['CURRTIME']并不总是像您期望的那样是一个数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM