Skip to content

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

Open

Description

@bilal-additio

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.

Activity

  1. added theissue type on Sep 29, 2025
  2. czosel commented on Sep 29, 2025

    @czosel
    Collaborator

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

    Playground link

  3. sorafujitani commented on Feb 5, 2026

    @sorafujitani

    @czosel @bilal-additio
    Since I was interested, I've created a PR for this.
    While I've contributed to prettier/prettier before, this is my first time contributing to prettier/plugin-php.
    In addition to reviewing the code, I'd appreciate any feedback on missing implementations or other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions