plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

`{` and `}` for variable property

Open alexander-akait opened this issue 7 years ago • 1 comments

Prettier 1.14.3

PHP Plugin 0.8.0

Input:

$var = $this->{$key};
$var = $this->value->{$method}();

Output:

$var = $this->$key;
$var = $this->value->$method();

Expected behavior:

Need vote

:+1: for $this->{$key} :heart: for $this->$key

I found what laravel, symfony and a lot of other projects use { and }, looks it is popular.

One note - we should respect { and } in source code, because it can be break php5 code http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect.

alexander-akait avatar Oct 11 '18 22:10 alexander-akait

My 2c: It's not often that I write code like this - usually it's a typo or copy/paste error, so adding curly braces would make it more explicit and obvious what is happening.

adamroyle avatar Oct 12 '18 04:10 adamroyle