FW: [PHP] Constants and "Here Document" Interpolation
| From: | Daniel R. Hansen | Date: | Sat, 01 Mar 2003 18:28:34 +0000 |
| Subject: | FW: [PHP] Constants and "Here Document" Interpolation | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137708@lists.php.net to get a copy of this message | ||
Actually I did try it and couldn't think of a way to work around the matter.
Thanks for the suggestion.
-----Original Message-----
From: Ernest E Vogelsinger [mailto:ernest@vogelsinger.at]
Sent: Saturday, March 01, 2003 12:56 PM
To: Daniel R. Hansen
Cc: php-general@lists.php.net
Subject: Re: [PHP] Constants and "Here Document" Interpolation
At 16:56 01.03.2003, Daniel R. Hansen said:
--------------------[snip]--------------------
>Can anyone tell me if it is possible (and how) to use defined constants
>within "here document" content? I've not been successful finding anything
>on this in the online docs.
--------------------[snip]--------------------
You simply could have tried it - it's trivial.
The answer: no, you cannot have a constant within a string, be it heredoc
or quoted. A constant must always reside on "native code level".
However you can easily concatenate strings and heredocs - both of the
examples below work correctly:
define('A_CONSTANT', 1);
$text1 = <<<EOT
This heredoc text contains the constant A_CONSTANT (
EOT
. A_CONSTANT . <<< EOT
) outside the heredoc construct...
EOT;
$text2 = "This quoted text contains the constant A_CONSTANT (" .
A_CONSTANT .
") outside the string quotes...";
echo "$text1<br />$text2";
Output:
This heredoc text contains the constant A_CONSTANT (1) outside the heredoc
construct...
This quoted text contains the constant A_CONSTANT (1) outside the string
quotes...
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/