Skip to content

Commit eff72ee

Browse files
committed
Fix nikic#718: PrettyPrinter breaks nested ternaries
Mark ternary as non-associative operator, as left-associative use is deprecated in PHP 7.4 and removed in PHP 8.0.
1 parent 658f1be commit eff72ee

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/PhpParser/PrettyPrinterAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class PrettyPrinterAbstract
6666
BinaryOp\BooleanAnd::class => [120, -1],
6767
BinaryOp\BooleanOr::class => [130, -1],
6868
BinaryOp\Coalesce::class => [140, 1],
69-
Expr\Ternary::class => [150, -1],
69+
Expr\Ternary::class => [150, 0],
7070
// parser uses %left for assignments, but they really behave as %right
7171
Expr\Assign::class => [160, 1],
7272
Expr\AssignRef::class => [160, 1],

test/code/prettyPrinter/expr/parentheses.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $a = $b = $c = $d = $f && true;
5959
($a = $b = $c = $d = $f) && true;
6060
$a = $b = $c = $d = $f and true;
6161
$a = $b = $c = $d = ($f and true);
62-
$a ? $b : $c ? $d : $e ? $f : $g;
62+
(($a ? $b : $c) ? $d : $e) ? $f : $g;
6363
$a ? $b : ($c ? $d : ($e ? $f : $g));
6464
$a ? $b ? $c : $d : $f;
6565
$a ?? $b ?? $c;

0 commit comments

Comments
 (0)