note 25484 added to tokens

From: Date: Wed, 25 Sep 2002 16:19:09 +0000
Subject: note 25484 added to tokens
Groups: php.notes 
Request: Send a blank email to php-notes+get-37233@lists.php.net to get a copy of this message
if you get a parse error saying that there was an unexpected T_ENCAPSED_AND_WHITESPACE, you've probably got an array within double quoted strings being parsed incorrectly. For example: $foo = $_GET['foo']; echo "foo is $foo"; // works fine However, echo "foo is $_GET['foo']"; // parse error Inside double-quoted strings, an identifier found within square brackets (after a variable, of course) is parsed as a string index. This identifier must be either a string, another variable, or a number. Since the single-quote around foo doens't fit (to the parser, anyway) any of these tokens, you get the parse error. To remove the error, remove the single quotes, OR use the curly-brace syntax (recommended, as it's required for more complex substitution anyway). echo "foo is {$_GET['foo']}"; // works echo "foo is $_GET[foo]"; // also works -- http://www.php.net/manual/en/tokens.php http://master.php.net/manage/user-notes.php?action=edit+25484 http://master.php.net/manage/user-notes.php?action=delete+25484 http://master.php.net/manage/user-notes.php?action=reject+25484

« previous php.notes (#37233) next »