The php.net RFC channel has announced the Heredoc and Nowdoc syntax updates for PHP 7.3. This update focuses on code readability:
## From the current implementation of PHP 7.2, like this simple example:Heredoc and Nowdoc has a very strict syntax, which sometimes makes many developers avoid it because they look very ugly in the code, making the code less readable. In response to this problem, this update has made the following two changes to the syntax:
supports the indentation of closing tags;
Line breaks for closing tags are no longer forced;
<?php class foo { public $bar = <<<EOT bar EOT; }
<?php class foo { public $bar = <<<EOT bar EOT; }
<?php // 4 个缩进空格 echo <<<END a b c END; /* a b c */
<?php stringManipulator(<<<END a b c END); $values = [<<<END a b c END, 'd e f'];
<?php $name = 'Example'; $str = <<<'EOD' Example of string $name spanning multiple lines using nowdoc syntax. EOD;
Example of string $name spanning multiple lines using nowdoc syntax.
In computer science, a here document, also known as a heredoc, hereis, here-string or here-script, is a file input or data stream input: a block of code that can be treated as a complete file. It can save whitespace characters such as line breaks or indents in the text. Some languages allow variable substitution and command substitution within strings.Improvements in Heredocs and Nowdocs will make your PHP code more readable and error-prone. On the other hand, the output is more concise and direct because the indentation that would close the markup is removed. Get more information It is recommended to read the official change document - flexible Heredoc and Nowdoc Syntaxes RFC. PHP official documentation Heredoc and Nowdoc.