简体   繁体   English

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

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

How do i get rid of this error? 我如何摆脱这个错误?

code: 码:

        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);
            }
        }

I am hitting that error in that last if statement's line: 我在最后一个if语句行中遇到该错误:

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

And i know that $array['Entity ID']=4 而且我知道$array['Entity ID']=4

How do i fix this? 我该如何解决?

Thanks :-) 谢谢 :-)

UPDATE 3 更新3
I removed the dumps as they are a bit sensitive 我删除了转储,因为它们有点敏感

There's only three possibilities either $thisC , $thisC['CURRTIME'] , or $array is not an array... 只有三种可能性: $thisC$thisC['CURRTIME']$array不是数组...

You can alter the function signature to protect against the latter: 您可以更改功能签名以防止后者:

function get_green_entities($c, array $array)

If $array is the problem, it will get triggered when calling the function. 如果$array是问题,则在调用该函数时将触发它。 So now if the problem persists, you know it has something to do with $thisC . 因此,如果问题仍然存在,您现在知道它与$thisC

Calling var_dump on the line before the error should make it obvious what the problem is. 在错误发生之前在行上调用var_dump可以使问题很明显。

Consider the behavior of: 考虑以下行为:

$array = 'test';

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

So I would think the problem is that $thisC['CURRTIME'] is not always an array like you expect. 因此,我认为问题在于$thisC['CURRTIME']并不总是像您期望的那样是一个数组。

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

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