note 25484 deleted from tokens by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 27 Jun 2004 16:45:23 +0000 |
| Subject: | note 25484 deleted from tokens by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71941@lists.php.net to get a copy of this message | ||
Note Submitter: yomama_AT_ucsd.edu
----
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