Skip to content

Give concatenation its PHP 8 precedence in php8 - #38

Merged
TomasVotruba merged 1 commit into
mainfrom
php8-concat-precedence
Nov 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
php8-concat-precedence

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

PHP 8.0 (RFC) made . bind looser than +, -, << and >>. The php8 grammar still had PHP 7's order - . on the same level as +/- - so

"Sum: " . $a + $b

parsed as ("Sum: " . $a) + $b instead of "Sum: " . ($a + $b), the way PHP 8 runs it. Printing back was unaffected, but any tool reasoning about the expression saw the wrong tree.

The precedence block now matches zend_language_parser.y:

%left T_PIPE
%left '.'
%left T_SL T_SR
%left '+' '-'

php5/php7 grammars are untouched - PHP 7 keeps the old order. The grammar conflict count is unchanged (3 shift/reduce, 7 reduce/reduce).

Tests: . vs +, . vs <<, and a . chain under === (stays left-associative, above comparison); the first two fail without the change. Verified downstream: reco's tests and Rector fixtures parity are unchanged against this branch.

PHP 8.0 made . bind looser than +, - and the shifts, but the php8 grammar
kept PHP 7's order, so "a" . 1 + 2 parsed as ("a" . 1) + 2 instead of
"a" . (1 + 2).
@TomasVotruba
TomasVotruba merged commit c37189f into main Nov 23, 2026
5 checks passed
@TomasVotruba
TomasVotruba deleted the php8-concat-precedence branch November 23, 2026 17:51
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