Page 1 of 1

Cannot use string offset as array

Posted: Sat Nov 07, 2009 6:43 am
by Dabrowski
This morning my script that worked fine is giving me errors.

Err: Cannot use string offset as array

It seems that every time I use $_SESSION['item']['item2'] it gives me the error.

In the setup, I set:

Code: Select all

$_SESSION['user']['level'] = 9
Later in the script, anywhere I check:

Code: Select all

if ($_SESSION['user']['level'] == 9)
I get the error.

It seems to handle if I only use the top level. $_SESSION['user'] == 9

Re: Cannot use string offset as array

Posted: Sat Nov 07, 2009 7:06 am
by Eric!
Are you sure it is getting set? Try this right before the line that causes the error.

Code: Select all

echo '<pre>.'.print_r($_SESSION).'</pre>';

Re: Cannot use string offset as array

Posted: Sat Nov 07, 2009 7:16 am
by Dabrowski
Yes, I did in a previously included file. If I check it in the same file I'm getting the error, it won't show since it fails.

I just tried a stripped down version in a single file and everything works, so now to show a live example would be problematic.

But yes, it was set.

Re: Cannot use string offset as array

Posted: Sat Nov 07, 2009 7:22 am
by Dabrowski
I think I fixed it. I another file was unsetting $_SESSION.

Re: Cannot use string offset as array

Posted: Sat Nov 07, 2009 7:25 am
by Eric!
Dabrowski wrote:Yes, I did in a previously included file. If I check it in the same file I'm getting the error, it won't show since it fails.
So how do you know it was set? I don't see any other problems, but we don't have access to your code either.

Edit: we posted at the same time...so it's set now