PHP-Parser
PHP-Parser copied to clipboard
Bug: Concatenation changes the order of elements by prettyprinter
Given the code:
<?php
('abc' . 1) + 2;
And running the parser on the original and PrettyPrinter format we get different AST.
Original:
array(
0: Stmt_Expression(
expr: Expr_BinaryOp_Plus(
left: Expr_BinaryOp_Concat(
left: Scalar_String(
value: abc
)
right: Scalar_Int(
value: 1
)
)
right: Scalar_Int(
value: 2
)
)
)
)
Prettied:
array(
0: Stmt_Expression(
expr: Expr_BinaryOp_Concat(
left: Scalar_String(
value: abc
)
right: Expr_BinaryOp_Plus(
left: Scalar_Int(
value: 1
)
right: Scalar_Int(
value: 2
)
)
)
)
)
I assume you actually meant:
<?php
('abc' . 1) + 2;
The print is correct for PHP 7, but not for PHP 8, which changed concat precedence.
Yes, I meant concatenation, sorry.
Even for a single PHP version, the most recent one 8.4.1, PrettyPrinter changes the precedence of operations and the output is different in two cases: https://3v4l.org/KD1RL#v8.4.1