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

Readonly properties crash Prettier when order is not "{access modifier} readonly"

Open alexkramer98 opened this issue 3 years ago • 0 comments

@prettier/plugin-php v0.18.4 Playground link

Input:

<?php

class Foo {
	public function __construct(readonly private string $baz){}
}

Output:

Parse Error : syntax error, unexpected 'private' (T_PRIVATE), expecting T_VARIABLE on line 4

  2 |
  3 | class Foo {
> 4 | 	public function __construct(readonly private string $baz){}
    | 	                                    ^
  5 | }

The other way around works just as expected (private readonly).

I was unable to find anything about the order of those modifiers in the RFC.

However, php executes the script just fine, so the code itself seems valid.

alexkramer98 avatar Mar 28 '22 15:03 alexkramer98

I have encountered this too, I think it will need to be fixed in the parser.

cseufert avatar Sep 09 '22 00:09 cseufert

Released in 0.19.1 :tada:

czosel avatar Sep 13 '22 17:09 czosel