fix: use PHP 8 concatenation precedence in the pretty printer
The precedence table gave "." the same precedence as "+" and "-", which is
the PHP 7 ordering. PHP 8.0 lowered "." below the arithmetic and shift
operators, so printing ('abc' . 1) + 2 produced 'abc' . 1 + 2, which PHP 8
reparses as 'abc' . (1 + 2). The same applied to "-", "<<" and ">>".
The printer already targets a specific PHP version and already varies
parenthesization by version, so select the concatenation precedence the same
way: for a target of PHP 8.0 or newer, place "." between the shift operators
and the pipe operator, matching the PHP8 block of grammar/php.y. Targets below
8.0 keep the PHP 7 table, which is correct for them and produces unchanged
output.
Fixes #1041
This commit is contained in:
1 parent
09376a3b68
commit
00e7c77eee
4 files changed
+86
-4
No files matched your search
@@ -67,6 +67,10 @@ The behaviors controlled by `phpVersion` (defaults to PHP 7.4) are:
|
||||
for this has been removed with the introduction of flexible heredoc/nowdoc strings.
|
||||
* For PHP >= 7.3, heredoc/nowdoc strings are indented just like regular code. This was allowed with
|
||||
the introduction of flexible heredoc/nowdoc strings.
|
||||
* For PHP >= 8.0, the concatenation operator is treated as binding less tightly than the arithmetic
|
||||
and shift operators, matching the precedence change in PHP 8.0. For older versions `.` keeps the
|
||||
same precedence as `+` and `-`. This determines where parentheses are required, so the printed
|
||||
code only reparses into the same AST under the targeted version.
|
||||
|
||||
The default pretty printer does not provide functionality for fine-grained customization of code
|
||||
formatting.
|
||||
|
||||
Reference in new issue
Block a user