Skip to content

Commit

Permalink
Support fixup for dynamic class const name
Browse files Browse the repository at this point in the history
This is new in PHP 8.3.
  • Loading branch information
nikic committed Feb 26, 2023
1 parent 7b4a8c1 commit e9416a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/PhpParser/PrettyPrinterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,10 @@ protected function initializeFixupMap(): void {
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,
Expand Down
3 changes: 3 additions & 0 deletions test/code/formatPreservation/fixup.test
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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');
-----
<?php
$a ();
Expand All @@ -80,3 +82,4 @@ $x instanceof ('Foo');
(FOO) :: bar;
(FOO) :: $bar;
(FOO) :: bar();
Foo :: {$bar};

0 comments on commit e9416a0

Please sign in to comment.