HEELPBOOK - PHP - Fatal error: Cannot use string offset as an array in... ####################### PHP5 Error message that is caused by attempting to assign a value to an array element of a variable that is declared as a string. Example that generates error: $foo='bar'; $foo[0]='bar'; Get error message Fatal error: Cannot use string offset as an array in... ##### Explanation: $foo was declared as a string in $foo='bar'. $foo[0] is trying to append an element onto a string variable. Example that does not generate error: $foo[0]='bar'; $foo='bar'; Does NOT generate error. ####### Explanation: $foo[0]='bar' instantiates variable $foo as array since it has not been instantiated. Then assigns 'bar' to element $foo[0]. $foo='bar' implicitly re-declares $foo as a string and assigns 'bar' to it. Example that does not generate error: $foo='bar'; $foo=array(); $foo[0]='bar'; ########## Explanation: $foo='bar' implicitly declares $foo as a string variable then assigns 'bar' as the value. $foo=array() explicitly re-declares $foo as an array. $foo[0]='bar' can now be executed as $foo is declared as an array. ############ ARTICLE INFO ############# Article Month: April Article Date: 25/04/2012 Permalink: http://heelpbook.altervista.org/2012/php-fatal-error-cannot-use-string-offset-as-an-array-in/ Source: http://informationideas.com/news/2006/06/14/fatal-error-cannot-use-string-offset-as-an-array-in/ Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook