prettier / prettier/plugin-php

Bug: Prettier will remove parenthesis around new objects calling a function

Open
#2,440 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

If I have a line like so:

$timestamp = (new DateTimeImmutable())->format(DATE_ATOM);

Prettier will reformat it as:

$timestamp = new DateTimeImmutable()->format(DATE_ATOM)

which is not valid PHP code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PHP snippet from the issue and trace the formatter's handling of parenthesized new-object expressions and chained method calls. Done means Prettier preserves the parentheses required for valid PHP output and a regression test covers this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.