php-parser icon indicating copy to clipboard operation
php-parser copied to clipboard

Syntax error when end of heredoc does not have a space between it and the concatenation operator

Open Spice-King opened this issue 5 months ago • 2 comments

This is a short one for reproduction.

This one throws (SyntaxError: Parse Error : syntax error, expecting T_END_HEREDOC on line 4)

<?php
echo <<<EOS

EOS. "";

This does not.

<?php
echo <<<EOS

EOS . "";

Both are valid PHP code, with the same net effect. Though, the examples are basically as minimal as can be, to the point it would be nonsensical in real code. Replace "" with a variable and add some meat to heredoc, then you get something reasonable. Like something you might get in a test, like where I found this.

By the looks of it, it's something added in PHP 7.3, and was missed in #506, so should be easy to add to https://github.com/glayzzle/php-parser/blame/c702357f7435af363051a947b64d1e064cca014b/src/lexer/strings.js#L10 and have a test added.

Spice-King avatar Jun 09 '25 20:06 Spice-King

@Spice-King thanks for the bug report! PRs welcome :)

czosel avatar Jun 11 '25 18:06 czosel

It's a one line fix, but many more lines of tests to write. I'll write up some suitable tests when I find some dead time next week for a PR. Been spinning far too many plates at work.

Spice-King avatar Jun 13 '25 20:06 Spice-King