简体   繁体   中英

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:

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

And i know that $array['Entity ID']=4

How do i fix this?

Thanks :-)

UPDATE 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...

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. So now if the problem persists, you know it has something to do with $thisC .

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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