Re: here document
| From: | Lars Torben Wilson | Date: | Thu, 02 Nov 2000 05:42:14 +0000 |
| Subject: | Re: here document | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23323@lists.php.net to get a copy of this message | ||
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|
+----------------------------------------------------------------+