note 35677 added to language.types.string
| From: | ralph at maxsoft dot com | Date: | Wed, 10 Sep 2003 16:36:21 +0000 |
| Subject: | note 35677 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55954@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35677
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35677&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35677&report=yes