prettier / prettier/plugin-php

Parentheses around nested ternary expressions are removed, causing syntax error in PHP 8.0

Open
#2,115 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

@prettier/plugin-php v0.19.2
Playground link

Input:

<?php

var_dump((1 ? 2 : 3) ?: 4);

Output:

<?php

var_dump(1 ? 2 : 3 ?: 4);

Leads to this syntax error in PHP 8.1:

Nested ternary expressions are deprecated since PHP 7.4

Note: It does work as expected when you don't make use of a shorthand ternary operator (?:).

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

Reproduce the formatting with the linked PHP playground using the provided nested ternary input and compare it with the shown output. Trace the formatter path responsible for removing parentheses, then verify that formatting preserves the required parentheses and no longer produces the PHP 8.1 syntax error.

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
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.