Skip to content
Advertisement

Cannot use string offset as an array in php

I’m trying to simulate this error with a sample php code but haven’t been successful. Any help would be great.

“Cannot use string offset as an array”

Advertisement

Answer

For PHP4

…this reproduced the error:

JavaScript

For PHP5

…this reproduced the error:

JavaScript

(From bugs.php.net actually)

Edit,

so why doesn’t the error appear in the first if condition even though it is a string.

Because PHP is a very forgiving programming language, I’d guess. I’ll illustrate with code of what I think is going on:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement