Forum Moderators: coopster
Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping. It shares some features in common with the SGML <![CDATA[ ]]> construct, in that it declares a block of text which is not for parsing.
[php.net...]
Very cool. Not sure how much I'd use this, though, before I just closed my php tags and reopened them afterwards.
$var = <<<'HTML'
and she said "He's so blah blah" but that isn't blah blah
HTML;
Opposed to:
$var = 'and she said "He\'s so blah blah" but that isn\'t blah blah';
$var = "and she said \"He's so blah blah\" but that isn't blah blah";
$var_now = <<<'HTML'
and she said "He's so blah blah" but that isn't blah blah
HTML;
$var_here = <<<HTML
and she said "He's so blah blah" but that isn't blah blah
HTML;
echo $var_now;
echo $var_here;
Give you the same thing. So nothing new from heredoc.
The only use I have found so far is for declaring class variables.
<?php
class foo {
// As of PHP 5.3.0
public $bar = <<<'EOT'
bar
EOT;
}
?>