Skip to content

Drop a trailing open tag from the end token in the formatter - #19

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

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

Conversation

@danslo

@danslo danslo commented Nov 16, 2026

Copy link
Copy Markdown

A file whose last open tag holds nothing but comments:

<?php
foo();
?>
<?php
// c

is printed as foo();<?php // c, which no longer parses. The parser keeps the second open tag and the comment on the root's end token, and the formatter turns the closing tag into a semicolon, so the printer writes the open tag inside PHP code.

The formatter now drops open tags from the end token, unless the last statement is inline HTML, where the printer is out of PHP code. Added a formatter test.

The end token holds what follows the last statement. After a closing tag
that the formatter makes a semicolon, an open tag there, '?>\n<?php // c',
printed inside PHP code: ';<?php // c'.
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