Re: Constants in strings
| From: | Geoff Lane | Date: | Wed, 06 Jul 2011 12:01:34 +0000 |
| Subject: | Re: Constants in strings | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313946@lists.php.net to get a copy of this message | ||
On Wednesday, July 6, 2011, Dave Wilson wrote:
> OK. We all know that constants cannot be accessed directly via their
> name in double-quoted or heredoc strings.
FWIW, this looked like it might be a right royal PITA for me ATM.
However, I've got a work-around.
With about a dozen scripts written using 'heredoc', I discover the
need to include extra information for which I required a constant. The
answer for me was to initialize a variable to have the same value as
the constant and to use that in the heredoc string. e.g:
define ('KONST', 100);
$konst = KONST;
echo <<<END
Some sample text in which we need $konst
END;
A similar approach is to declare a 'pseudo-constant' variable instead
of defining the constant (e.g. $konst=100 instead of the first two
lines of code in the above sample).
HTH,
--
Geoff