prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.74k stars 126 forks source link

Dollar sign from variable name swallowed in double quoted Strings #2177

Open FrankNagel opened 1 year ago

FrankNagel commented 1 year ago

@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.

cseufert commented 1 year ago

The "${a}" syntax is now deprecated, with a plan to remove it in future PHP versions. see: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation