I get a strange PHP error after updating my php version to 5.4.0-3.
I have this array:
Array
(
[host] => 127.0.0.1
[port] => 11211
)
When I try to access it like this I get strange warnings
print $memcachedConfig['host'];
print $memcachedConfig['port'];
Warning: Illegal string offset 'host' in ....
Warning: Illegal string offset 'port' in ...
I really don't want to just edit my php.ini and re-set the error level.
Before to check the array, do this:
Please try this way.... I have tested this code.... It works....
The error
Illegal string offset 'whatever' in...
generally means: you're trying to use a string as a full array.That is actually possible since strings are able to be treated as arrays of single characters in php. So you're thinking the $var is an array with a key, but it's just a string with standard numeric keys, for example:
You can see this in action here: http://ideone.com/fMhmkR
For those who come to this question trying to translate the vagueness of the error into something to do about it, as I was.
There are a lot of great answers here - but I found my issue was quite a bit more simple.
I was trying to run the following command:
and I was getting this
illegal string
error on$x['name']
because I hadn't defined the array first. So I put the following line of code in before trying to assign things to$x[]
:and it worked.
Just incase it helps anyone, I was getting this error because I forgot to unserialize a serialized array. That's definitely something I would check if it applies to your case.
It's an old one but in case someone can benefit from this. You will also get this error if your array is empty.
In my case I had:
which I changed to: