At 10/25/2006 11:24 PM, Robert Cummings wrote:
Now, the thing that I dislike about heredoc for such small strings is
the switching between heredoc mode and the switching back. It's ugly on
the scale of switching in and out of PHP tags.

It's so interesting that some details bug some people and others bug others. In an expression such as this:

echo '<option value="' . $day . '"' . $selected . '>' . $day . '</option>';

...I count eight transitions (instances of switching between PHP syntax and output text) -- one each time you open or close a quote -- compared to just two transitions (the opening & closing labels) for the comparable heredoc statement:

        print <<< hdDay
        <option value="$day"$sSelected>$day</option>

hdDay;


it would be less ugly if
the closing delimiter didn't have to be at the beginning of it's own
line in which case code could still maintain indentation formatting.

I agree. Too bad the PHP developers didn't come up with a special symbol for heredoc closing labels to give us more control over script formatting. I do however find this a fairly minor irritation, a small price to pay for heredoc's power.


To lighten the mess of heredoc I
personally use the following format:

    $foo = <<<_
        ...
_;

Nice and concise!  Thanks, I'll use that.


However that's only useful if indenting the content is not an issue.

I don't see how you draw that conclusion. Heredoc doesn't become useless if we need to indent the content, it just means we lose complete control over indenting every line of our PHP script. The functionality is still totally there.

This script indenting issue with heredoc is for me one of the few irritations of PHP. I love the language and the power that heredoc gives me. I'm also irritated by the class member syntax $this->that but I still use it as well.


> I ask because I use heredoc all the time, sometimes for inline code
> as above but most often for template assembly, maintaining HTML in
> external files that can be edited independently of the PHP logic.

I use a tag based template system, there's no PHP in my content so my
content files for the most part just look like more HTML.

This is a different topic, but also one close to my heart. Yes, I too use my own selector-based templating system. It does allow me to embed PHP variables into the template if I want, but the primary merge between plain HTML template and MySQL content happens through CSS-style selectors.


Hello <jinn:render name="email" selector="firstName"/>,

Cool.

My comparable example (but in an HTML context) would look like:

        Hello <span class="firstName">FIRSTNAME</span>,

where the engine replaces the content of the span with the value from the database based on a match of 'span.firstName' or perhaps just '.firstName'. (In this example the 'FIRSTNAME' content in the template is merely a place-holder to make it easier to preview the markup and isn't necessary to the merge process.)


| InterJinn Application Framework - http://www.interjinn.com |

Interesting project!  Good work.

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

Reply via email to