note 59565 added to language.types.string
| From: | Alex at osu1 dot php dot net | Date: | Fri, 09 Dec 2005 19:24:24 +0000 |
| Subject: | note 59565 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99866@lists.php.net to get a copy of this message | ||
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
?>
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59565
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59565&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59565&report=yes
Search -- http://master.php.net/manage/user-notes.php