note 59565 deleted from language.types.string by colder
| From: | colder@php.net | Date: | Tue, 17 Oct 2006 18:25:03 +0000 |
| Subject: | note 59565 deleted from language.types.string by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118648@lists.php.net to get a copy of this message | ||
Note Submitter: Alex
----
For heredocs, the manual is accurate. Many other descriptions on the web are not.
PHP always tries to evaluate variables. So if you want a $ sign, it always needs to be escaped or
in complex format, depending on the context. This is especially important if you are trying to do
an eval().
<?php
$foo = 1;
$code = <<<CODE
$bar = $foo;
CODE;
eval ($code); // doesn't work
?>
<?php
$foo = 1;
$code = <<<CODE
\$bar = \$foo;
CODE;
eval ($code); // $bar = $foo;
?>
<?php
$foo = 1;
$code = <<<CODE
\$bar = {$foo};
CODE;
eval ($code); // $bar = 1;
?>
<?php
$foo = 1;
$code = <<<CODE
{$bar} = {$foo};
CODE;
eval ($code); // doesn't work
?>