Repository navigation
Conversation
Without parentheses, `new` only takes a class name or a variable with property lookups, so `new ($a ?? $b)()` printed as `new $a ?? $b()` changed meaning, and `new (Foo::BAR)()` printed as `new Foo::BAR()` stopped parsing.
Dextheking1
reviewed
Oct 31, 2026
Dextheking1
left a comment
Contributor
There was a problem hiding this comment.
checked this one out. the paren drop is real: on the old printer $h formats to new static::$classes[$k] ?? Fallback::class($z), which calls the fallback as a function instead of instantiating it. with the fix, tests/new passes 34/34 and the new class-expression cases keep their parens, while plain cases like $i and $j stay bare. looks right.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since PHP 8.0,
newaccepts any expression in parentheses, but the printer only keeps the parentheses when that expression is a call or an array lookup. Laravel Prompts haswhich is printed as
That still parses, but as
(new static::$themes[static::$theme][$class]) ?? static::$themes["default"][$class]($this), so the fallback class is called as a function instead of being instantiated. Other forms change meaning the same way (new ($x . "Suffix")(),new ($cond ? A::class : B::class)(),new ($a->factory()->class)()) or stop parsing (new (Foo::BAR)(),new ("Foo")(),new ((string) $x)()).Without parentheses, PHP only accepts a class name or a variable after
new, optionally followed by property, nullsafe property or static property lookups.isNewClassReferencechecks for exactly that, and anything else keeps its parentheses. Calls and array lookups keep them as before, whilenew ($a->b)()andnew (static::$class)()still lose them.The new
tests/new/class-expression.phpcovers all these cases; before the change, its snapshot had the outputs above.yarn test(including the standalone build),AST_COMPARE=1 yarn test:nodeandyarn lintpass, no other snapshot changes, and Laravel'sThemes.phpnow formats to the same AST as the input (checked with nikic/php-parser) and is stable on a second run.One case is still not handled:
new (FOO)()with a constantFOO. php-parser gives the samenamenode as fornew FOO(), so the printer can't tell them apart.