PHP 5.3 introduced the nowdoc syntax. When no variable extrapolation or escape sequences are needed, a nowdoc should be used instead of a heredoc.
Related PHPCompatibility sniff(s):
Newkeywords
PHP manual references:
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.
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
// This heredoc should not be touched by the sniff!
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
And fix these to:
$str = <<<'EOD'
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
// Second example should be untouched.
Notes for implementation of the sniff:
Beware of escaped variables in heredocs \$variables. These will not be extrapolated.
Beware of escape sequences which necessitate the use of heredoc over nowdoc.
Short description
PHP 5.3 introduced the
nowdoc
syntax. When no variable extrapolation or escape sequences are needed, anowdoc
should be used instead of aheredoc
.Related PHPCompatibility sniff(s):
Newkeywords
PHP manual references:
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
Example code:
Detect the following code pattern(s):
And fix these to:
Notes for implementation of the sniff:
\$variables
. These will not be extrapolated.Prior art
heredoc_to_nowdoc