0

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

7
  • Can you give us a var_dump of $thisC? Commented Mar 21, 2011 at 18:25
  • Which specific line(s) of code are you getting the offset error on, please? Commented Mar 21, 2011 at 18:31
  • i say above which line im getting the error. that did not change Commented Mar 21, 2011 at 18:31
  • what is the value of $array['Entity ID'] Commented Mar 21, 2011 at 18:34
  • the value of $array['Entity ID'] is 4 Commented Mar 21, 2011 at 18:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

9 Comments

@Neal, you say that it is "last successful." I took that to mean the one before the error is caused, which doesn't really offer an explanation. See my appended example in my answer for behavior that looks similar to what you are describing.
yes. i put the dump in the if statement. before the var was set
@Neal, you would only get that error message when setting multiple components of a string variable like $a[0][1] = 'bar', due to PHP's odd type juggling, so given the code you've provided it has to be $thisC is not an array. You may want to try if (!is_array($thisC)) die('...'); to check against that. You could also try replacing the reference with a copy/paste of the original to make sure something odd isn't happening with that.
than how when i print_r($thisC) i get an array result?
Note that print_r(NULL) (or '') displays nothing.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.