plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Bug: Prettier incorrectly adds parentheses when using new with a static property

Open bilal-additio opened this issue 4 months ago • 1 comments

Description:

When formatting code with Prettier in PHP 8.4, parentheses are incorrectly added to a static property when instantiating an object. This causes a syntax error and breaks the application.

Example:

Before Prettier:

$identifier = new Yii::$app->class([]);

After Prettier:

$identifier = new Yii::$app()->class([]);

Expected behavior: Prettier should leave the code as-is without adding parentheses when using new on a static property.

Actual behavior: Prettier adds () to the static property, resulting in invalid syntax.

Impact: Code breaks when executed, causing runtime errors in applications using this pattern.

bilal-additio avatar Sep 26 '25 13:09 bilal-additio

Hi @bilal-additio, thanks for the bug report! Contributions are welcome :-)

Playground link

czosel avatar Sep 29 '25 06:09 czosel