note 35677 deleted from language.types.string by vincent
| From: | vincent@php.net | Date: | Wed, 10 Sep 2003 16:50:59 +0000 |
| Subject: | note 35677 deleted from language.types.string by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55956@lists.php.net to get a copy of this message | ||
Note Submitter: ralph@maxsoft.com
----
Heredoc syntax is ugly and violates indenting conventions. Fortunately, a single underscore is
acceptable as the heredoc start/end identifier. The following illustrates a style that looks
*almost* plausible even in the midst of multiple indentations.
<?php
echo "<table>";
$z = 142857;
if ($trouble) {
$x = "prisoner";
echo <<<_
<tr>
<td>This cell contains a $x</td>
</tr>
_;
$result = -1;
} else {
$y = "constant";
echo <<<_
<tr>
<td>This cell contains a $y: $z</td>
</tr>
_;
$result = 1;
}
echo "</table>";
?>
I find using heredoc this way to be worth the trouble, because the syntax allows direct embedding of
variables into HTML without any fuss or backslashes, which is a big win for readability.