This RFC has been superseded by PHP RFC: Flexible Heredoc and Nowdoc Syntaxes
The heredoc and nowdoc syntax provide the ability to create multiline strings without the hassle of having to escape all inner quotation marks. These syntaxes, however, have been eschewed in-part because of their inflexibility with respect to indentation. They break the code layout, which makes things look ugly and harder to read. This proposal therefore seeks to enable the closing marker to be indented.
The indentation of the closing marker will change code from:
<?php class foo { public $bar = <<<EOT bar EOT; }
To:
<?php class foo { public $bar = <<<EOT bar EOT; }
The indentation of the closing marker dictates the amount of whitespace to strip from each line within the heredoc/nowdoc. So let's demonstrate these semantics with a few examples:
// no indentation echo <<<END a b c END; /* a b c */ // 1 space of indentation echo <<<END a b c END; /* a b c */ // 2 spaces of indentation echo <<<END a b c END; /* a b c */ // 3 spaces of indentation echo <<<END a b c END; /* a b c */ // 4 (or more) spaces of indentation echo <<<END a b c END; /* a b c */
Tabs are supported as well. If tabs and spaces are intermixed (for whatever reason...), then each space and each tab is considered as 1 indentation. So if the closing marker is indented by 1 tab, and the heredoc/nowdoc body is indented by spaces, then regardless of the closing marked *looking* further indented, only 1 bit of whitespace will still be stripped from each line:
// 1 tab indentation echo <<<END a b c END; /* a b c */
Moral of the story: don't mix spaces and tabs...
If the closing marker was within the body of the text, where it was the first thing (minus whitespace), terminated with a `;`, and had a newline after it, then this will now be considered the ending marker. (As you can probably tell, this is a fairly unrealistic scenario...)
The next PHP 7.x version (or 8.0, whichever comes next)
None that I know of.
A simple yes or no for this feature (with a 2/3 majority required).
Initial implementation: https://github.com/php/php-src/compare/master...tpunt:heredoc-nowdoc-indentation
Language specification: will be updated if the RFC is accepted.
After the project is implemented, this section should contain
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.