You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 = <<<EODExample of stringspanning multiple linesusing heredoc syntax.EOD;
// This heredoc should not be touched by the sniff!echo<<<EOTMy name is "$name". I am printing some $foo->foo.Now, I am printing some {$foo->bar[1]}.This should print a capital 'A': \x41EOT;
And fix these to:
$str = <<<'EOD'
Example of stringspanning multiple linesusing 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.
Prior art
CS-fixer: heredoc_to_nowdoc
The text was updated successfully, but these errors were encountered:
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
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double (escape codes)
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
The text was updated successfully, but these errors were encountered: