Skip to content

Keep heredoc labels and nowdocs, and end the closing label's line - #27

Open
danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-heredoc
Open

danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-heredoc

Conversation

@danslo

@danslo danslo commented Nov 18, 2026

Copy link
Copy Markdown

The formatter wrote every heredoc and nowdoc as <<<EOT:

  • A nowdoc became a heredoc, so PHP interpolated its body: $x and \t in <<<'TXT' turned into a variable and a tab.
  • A body line starting with EOT ended the heredoc early.

It now keeps the label and the nowdoc quotes. Where a body line would end the heredoc, it picks another label (TXT1, TXT2, ...). The closing token is now T_END_HEREDOC instead of T_START_HEREDOC.

The printer also wrote what follows a heredoc on the closing label's line, for example EOT), 1;, which PHP before 7.3 rejects. It now starts a new line there unless a semicolon follows.

Added formatter tests for a nowdoc, a body line holding the label, and a heredoc passed as an argument.

The formatter wrote every heredoc as <<<EOT: a nowdoc became a heredoc, whose body PHP interpolates, and a body line starting with EOT ended it early. The printer wrote ) or , right after the closing label, which PHP before 7.3 rejects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant