NYCPHP Meetup

NYPHP.org

[nycphp-talk] heredoc string formatting question

csnyder chsnyder at gmail.com
Sat Aug 12 13:14:54 EDT 2006


On 8/12/06, Daniel Convissor <danielc at analysisandsolutions.com> wrote:
> On Thu, Aug 10, 2006 at 06:07:17PM -0400, Cliff Hirsch wrote:
> > Thanks to all -- excellent suggestions all around. In summary, heredoc
> > seems to be a waste. Too much room for error with a finicky editor and
> > no major added benefit.
>
> Huh?  The pure PHP approach via heredoc or plain old quoted
> syntax is the straight ahead way to go.  If you want the template
> separated from the logic, put it in an include file.
>
> What's the room for error?  The editor changes the line endings from
> CRLF to LF or vice versa?  BFD.  All email programs can read either.
> Inadvertently indenting the heredoc's endpoint?  I've never had that
> happen in all my seven years of using PHP.
>
> Template engines and languages are what's complex, finicky and add
> notable processing overhead.
>
> This thread is talking about cutting butter with a chainsaw.
>
> --Dan

Sometimes you need a chainsaw, you know. ;-)

I'll take responsibility for the "editor flakiness" angle, because I
_have_ had it happen to me. Sure, it's dumb to run "indent code"
macros without looking for in-script formatted text, but faced with a
hundred lines of unindented spaghetti logic, that's what I did. And
then everything stopped working.

Heredoc is a fragile construction. Nothing else in php (with the
possible exception of extra linebreaks after ?>) breaks because of
whitespace or indentation issues. It's hardly a big deal, but every
now and then the small deals make a big difference.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list