Closed claudiu-cristea closed 2 years ago
The pretty printer will produce A . B . C
, not (A . B) . C
, see e.g. this test: https://github.com/nikic/PHP-Parser/blob/678ccbe0720549c51d30b76d094a117eac819e9e/test/code/prettyPrinter/expr/parentheses.test#L52
Closing this per above comment. Looking at the references PR, you simply nested the concat nodes in the wrong way (they are left-associative, not right-associative).
Initial report https://github.com/rectorphp/rector/issues/7188
Problem
I want concatenate 3 elements:
This produces
(A . B) . C
, but the parenthesis are useless. It should be, simply,A . B . C
Note that this not related to https://wiki.php.net/rfc/concatenation_precedence, as there it's about precedence of 2 different operators. Plus or minus (
+
/-
) combined with string concatenation (.
). That makes total sense. But in this case it's just a trivial left-to-right precedence. It's like1 + 2 + 3
. We don't write(1 + 2) + 3
, do we?Proposal
It should be possible to pass an array of parts (same as
Encapsed
). However, changing theConcat
signature would break backwards compatibility, so my proposal is to create a newConcatMultiple
(orConcatenate
?) and deprecateConcat
. I would provide a PR if there an agreement on this request.