The error Illegal string offset 'whatever' in...
generally means: you're trying to use a string as a full array.
(错误Illegal string offset 'whatever' in...
通常意味着:您正在尝试将字符串用作完整数组。)
That is actually possible since strings are able to be treated as arrays of single characters in php.
(这实际上是可能的,因为在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: (因此,您认为$ var是带有键的数组,但是它只是具有标准数字键的字符串 ,例如:)
$fruit_counts = array('apples'=>2, 'oranges'=>5, 'pears'=>0);
echo $fruit_counts['oranges']; // echoes 5
$fruit_counts = "an unexpected string assignment";
echo $fruit_counts['oranges']; // causes illegal string offset error
You can see this in action here: http://ideone.com/fMhmkR
(您可以在这里看到实际的效果: 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.
(对于那些遇到此问题的人,就像我一样,试图将错误的模糊性转化为解决该问题的方法。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…