prettier / prettier/plugin-php
Parentheses around nested ternary expressions are removed, causing syntax error in PHP 8.0
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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