变得非常烦人的错误:“致命错误:无法将字符串偏移量用作...中的数组” [英] getting really annoying error: "Fatal error: Cannot use string offset as an array in..."

查看:152
本文介绍了变得非常烦人的错误:“致命错误:无法将字符串偏移量用作...中的数组”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何消除此错误?

代码:

        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语句行遇到了该错误:

I am hitting that error in that last if statement's line:

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

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

我该如何解决?

谢谢:-)

更新3

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

UPDATE 3
I removed the dumps as they are a bit sensitive

推荐答案

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

There's only three possibilities either $thisC, $thisC['CURRTIME'], or $array is not an array...

您可以将函数签名更改为防范后者:

You can alter the function signature to protect against the latter:

function get_green_entities($c, array $array)

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

If $array is the problem, it will get triggered when calling the function. So now if the problem persists, you know it has something to do with $thisC.

在错误发生前的行调用 var_dump 应该可以清楚地知道问题出在哪里。

Calling var_dump on the line before the error should make it obvious what the problem is.

考虑以下行为:

$array = 'test';

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

所以我认为问题在于 $ thisC ['CURRTIME'] 并不总是像您期望的那样。

So I would think the problem is that $thisC['CURRTIME'] is not always an array like you expect.

这篇关于变得非常烦人的错误:“致命错误:无法将字符串偏移量用作...中的数组”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆