[thelist] [PHP] Heredoc and Constants

Simon Willison cs1spw at bath.ac.uk
Thu Aug 14 14:22:26 CDT 2003

Hi Keith,

Thursday, August 14, 2003, 5:21:15 PM, you wrote:
> I'm working on a theme for PHP-Nuke and would like to use Heredoc syntax
> [1] for big blocks of HTML (I'm sick of reading code with endless \" and 
> \n). The only problem is that Nuke stores language information as 
> constants. All the themes I've seen simply break out of the string to 
> include this information: "<p>"._CONSTANT."</p>", but this is extremely 
> inconvenient with Heredoc. I know constants can be referenced with the 
> constant('_CONSTANT') function, but there doesn't seem to be a way to embed 
> a function call, either.

I'm afraid it just isn't possible to referecne a constant within a
string (or HEREDOC) without breaking out of the string first. The only
solution is to assign the value from the constant to a normal variable
before the HEREDOC block:

$constant = _CONSTANT;

print <<<EOD
<h1>Hi there, $constant</h1>




More information about the thelist mailing list