From 6d2584bdf12a55573d20034f0f8e12ff2b7ede2c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 26 Feb 2023 16:00:35 +0100 Subject: [PATCH] Support fixup for dynamic class const name This is new in PHP 8.3. (cherry picked from commit e9416a0eaec601df910045a6f63361068cffddbf) --- lib/PhpParser/PrettyPrinterAbstract.php | 5 ++++- test/code/formatPreservation/fixup.test | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 8d48cdfb92..770d500928 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -1230,7 +1230,10 @@ protected function initializeFixupMap() { Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS], Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS], Expr\ArrayDimFetch::class => ['var' => self::FIXUP_DEREF_LHS], - Expr\ClassConstFetch::class => ['class' => self::FIXUP_STATIC_DEREF_LHS], + Expr\ClassConstFetch::class => [ + 'class' => self::FIXUP_STATIC_DEREF_LHS, + 'name' => self::FIXUP_BRACED_NAME, + ], Expr\New_::class => ['class' => self::FIXUP_NEW], Expr\MethodCall::class => [ 'var' => self::FIXUP_DEREF_LHS, diff --git a/test/code/formatPreservation/fixup.test b/test/code/formatPreservation/fixup.test index ec3afe61f2..0fd07f16d1 100644 --- a/test/code/formatPreservation/fixup.test +++ b/test/code/formatPreservation/fixup.test @@ -47,6 +47,7 @@ $x instanceof Foo; Foo :: bar; Foo :: $bar; Foo :: bar(); +Foo :: bar; ----- $stmts[0]->expr->name = new Expr\Variable('a'); $stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); @@ -64,6 +65,7 @@ $stmts[10]->expr->class = new Scalar\String_('Foo'); $stmts[11]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); $stmts[12]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); $stmts[13]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); +$stmts[14]->expr->name = new Expr\Variable('bar'); -----