Re: Constants in strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux