Skip to content

Commit

Permalink
Fix #718: PrettyPrinter breaks nested ternaries
Browse files Browse the repository at this point in the history
Mark ternary as non-associative operator, as left-associative use
is deprecated in PHP 7.4 and removed in PHP 8.0.
  • Loading branch information
nikic committed Sep 30, 2020
1 parent 658f1be commit eff72ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/PhpParser/PrettyPrinterAbstract.php
Expand Up @@ -66,7 +66,7 @@ abstract class PrettyPrinterAbstract
BinaryOp\BooleanAnd::class => [120, -1],
BinaryOp\BooleanOr::class => [130, -1],
BinaryOp\Coalesce::class => [140, 1],
Expr\Ternary::class => [150, -1],
Expr\Ternary::class => [150, 0],
// parser uses %left for assignments, but they really behave as %right
Expr\Assign::class => [160, 1],
Expr\AssignRef::class => [160, 1],
Expand Down
2 changes: 1 addition & 1 deletion test/code/prettyPrinter/expr/parentheses.test
Expand Up @@ -59,7 +59,7 @@ $a = $b = $c = $d = $f && true;
($a = $b = $c = $d = $f) && true;
$a = $b = $c = $d = $f and true;
$a = $b = $c = $d = ($f and true);
$a ? $b : $c ? $d : $e ? $f : $g;
(($a ? $b : $c) ? $d : $e) ? $f : $g;
$a ? $b : ($c ? $d : ($e ? $f : $g));
$a ? $b ? $c : $d : $f;
$a ?? $b ?? $c;
Expand Down

0 comments on commit eff72ee

Please sign in to comment.