RE: [PHP] here document
| From: | Jack Dempsey | Date: | Thu, 02 Nov 2000 05:55:01 +0000 |
| Subject: | RE: [PHP] here document | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23324@lists.php.net to get a copy of this message | ||
Thanks very much to all for the great info shared.
Torben, that's a perfect example. It is DEFINITELY a PITA to output form
variables with all these <?PHP echo $something;?> all over the place.
The fact that the here doc option also lets you use the variables allows for
some easily/quickly coded html that has the occasional variable in it...
all the best,
Jack Dempsey
-----Original Message-----
From: Lars Torben Wilson [mailto:torben@pinc.com]
Sent: Thursday, November 02, 2000 12:42 AM
To: Dean Hall
Cc: Jack Dempsey; php-general@lists.php.net
Subject: Re: [PHP] here document
Dean Hall writes:
> > anything like perl's
> > print<<EOF
> > blah blah blah
> > EOF
> >
> > ?
>
> There's no need for here documentation in PHP. PHP is embedded in HTML,
not
> the other way around. To do something like that, you'd do:
This is only true for simple scripts. For instance, I've got several
thousand lines of backend code with no HTML *anywhere*. Despite the
fact that PHP was originally designed to be easily embeddable in HTML,
for extensive, modular, and maintainable code bases, it is not
desirable to do so.
> <?
> // some PHP
> ?>
> blah blah blah
> <?
> some more PHP
> ?>
>
> Dean.
Well, it was added nearly a year ago for two reasons:
1) ease (subjective) of complex output, and
2) to get people to stop asking for it every 5 minutes. :)
For instance, the following is IMHO a PITA to type in:
?>
<table>
<tr>
<td><?php echo $name ?></td>
<td><?php echo $email ?></td>
</tr>
</table>
<?php
Whereas this feels a lot easier:
echo <<<EOT
<table>
<tr>
<td>$name</td>
<td>$email</td>
</tr>
</table>
EOT;
Plus, it allows to to assign the whole chunk to a variable, which you
can't do with the ?><?php method.
Sure, it's an overly simplified and contrived example. But it *can* be
a useful function which extends beyond the mere status of syntactic
sugar. YMMV.
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+