Re: What does "<<<" mean?

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

 



At 4/30/2007 03:38 PM, Philip Thompson wrote:
Ok, let's gather some stats to see how many people actually use the
heredoc syntax. I created this quick little form to gather the data.
It's takes 2 seconds (literally) - vote here:

http://thril.uark.edu/heredoc/

I'm interested in knowing if this is used a lot. If it is, then I may
consider tying it into my code (if it calls for it).


I recommend that you to make your decision about using heredoc based on whether the syntax itself makes good sense to you, not based on which number or percentage of other programmers use it.

I love using heredoc and I don't give a rat's ass if there are only three other people in the world who use it. It absolutely makes sense to me, helps me write better code with fewer errors and that's much easier to read. I know from previous discussions of this topic that it gives some people the freakin' heebee-jeebies. That's fine; different strokes; doesn't matter. It's just one tool.

I use heredoc mostly for SQL queries, for html blocks, for inline html assembly, and for other circumstances in which I'm merging literals & variables. If a statement gets messy with too many concatenations, I'll use heredoc. I use heredoc for much the same reasons I like to separate data from logic in separate files. The next best thing to importing text is to heredoc it in the script itself. Also heredoc can be a quick & dirty way of roughing out a script to get the logic right before exporting the text to a separate file.

Another commenter in this thread is correct: you can't get away with referring to an array variable in heredoc without using {curly braces} e.g. {$aArray['key']}. That and the fact that the termination symbol has to be at the left margin are minor disadvantages in my view, far outweighed by the difficulty in accurately writing and reading complex concatenations.

When I first started using PHP I thought that each heredoc label had to be unique. Turns out that's not true, and now I use the simple shorthand:

$sResult = <<<_
Some text.
_;

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
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