prettier / prettier/plugin-php

Dollar sign from variable name swallowed in double quoted Strings

Open
#2,177 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.4
Playground link

Input:

<?php

# simple syntax
# OK
"$foo[$index_var]";

# simple syntax with explicit name boundaries with curly brackets
# Not OK: prettier swallows the dollar sign from $index_var
"${foo[$index_var]}";

# complex (curly) syntax
# OK
"{$foo[$index_var]}";

Output:

<?php

# simple syntax
# OK
"$foo[$index_var]";

# simple syntax with explicit name boundaries with curly brackets
# Not OK: prettier swallows the dollar sign from $index_var
"${foo[index_var]}";

# complex (curly) syntax
# OK
"{$foo[$index_var]}";

In a double quoted string using the so called simple syntax with explicit variable boundaries given by curly brackets prettier swallows the dollar sign from a variable nested inside the boundaries.

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 with the linked Playground reproduction and compare the input and output for the explicitly bounded variable syntax inside a double-quoted string. Trace how that interpolation is formatted, then verify that the nested $index_var keeps its dollar sign while the other two examples remain unchanged.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.