Click here to get back home

constants in heredoc

 HomeNewsGroups | Search
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
constants in heredoc Jeff 12-29-2008
Posted by Jeff on December 29, 2008, 12:12 pm
Please log in for more thread options
How do I use a constant in a heredoc?


$sample = <<<sample_code


SOME_CONSTANT


sample_code;

echo $sample;



The constant in that case is just showing it's "name".

Jeff

Posted by =?ISO-8859-1?Q?=22=C1lvaro_G=2 on December 29, 2008, 12:20 pm
Please log in for more thread options
Jeff escribió:
> How do I use a constant in a heredoc?
>
>
> $sample = <<<sample_code
>
>
> SOME_CONSTANT
>
>
> sample_code;
>
> echo $sample;
>
>
>
> The constant in that case is just showing it's "name".

As far as I know you cannot. Heredoc is not as useful as it looks :)

Anyway, there's a user note that suggests a dirty trick:

http://es2.php.net/manual/en/language.types.string.php#74744



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Posted by Jeff on December 29, 2008, 10:38 pm
Please log in for more thread options
Álvaro G. Vicario wrote:
> Jeff escribió:
>> How do I use a constant in a heredoc?
>>
>>
>> $sample = <<<sample_code
>>
>>
>> SOME_CONSTANT
>>
>>
>> sample_code;
>>
>> echo $sample;
>>
>>
>>
>> The constant in that case is just showing it's "name".
>
> As far as I know you cannot. Heredoc is not as useful as it looks :)
>
> Anyway, there's a user note that suggests a dirty trick:
>
> http://es2.php.net/manual/en/language.types.string.php#74744

Thanks, the "dirty" trick is a bit of an understatement!

Jeff
>
>
>

Similar ThreadsPosted
question about HEREDOC March 15, 2005, 11:46 am
using heredoc for SQL statements January 16, 2006, 7:27 pm
Getting a function result while in heredoc December 19, 2006, 11:15 am
inclosed variable heredoc December 19, 2006, 5:06 pm
HEREDOC help, going quietly nuts October 20, 2007, 11:44 am
heredoc and array problems July 17, 2008, 2:05 pm
question about heredoc strings August 1, 2008, 12:03 pm
count newlines in heredoc variable July 30, 2008, 2:21 pm
Writing to Heredoc from Text Area Form May 31, 2007, 10:45 am
Php constants in php.ini November 27, 2005, 9:53 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap