Bug: Prettier will remove parenthesis around new objects calling a function
If I have a line like so:
$timestamp = (new DateTimeImmutable())->format(DATE_ATOM);
Prettier will reformat it as:
$timestamp = new DateTimeImmutable()->format(DATE_ATOM)
which is not valid PHP code.
fwiw it's valid in PHP 8.4 : https://3v4l.org/MtjXX
@nicoder thx, tho I'm on PHP 8.3 for some projects, would appreciate it if this rule could be disabled based on php.version in settings.json
I'm having the same problem.
Before:
return (new View) [...]
After:
return new View() [...]
Running PHP 8.2 so won't help if it would work on PHP 8.4.
Thanks for the bug report @gmitch215! Contributions welcome :-)
Are you correctly setting your PHP version in your .prettierrc.json and/or composer.json? The code that updates this does check for PHP 8.4 first...
https://github.com/prettier/plugin-php/blob/0c883a49850281077218007322f6149f853b2015/src/needs-parens.mjs#L130-L133