Skip to content

readonly keyword not accepted when it comes first in class property definition #1170

@hackel

Description

@hackel

Just came across this while testing against PHP-CS-Fixer's tests. Not super important, but still a bug.

<?php

class Test {
    readonly public int $test;
}

Prettier Output (php-parser 3.2.5):

[error] test.php: SyntaxError: Parse Error : syntax error, unexpected 'public' (T_PUBLIC), expecting T_VARIABLE on line 4
[error]   2 |
[error]   3 | class Test {
[error] > 4 |     readonly public int $test;
[error]     |             ^
[error]   5 | }

I thought this should have been solved by #997, but it looks like that only applied to promoted properties in the constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions