Skip to content

Readonly properties should be assignable outside the constructor #13003

@nafetsrybak

Description

@nafetsrybak

Feature request

As Larry Garfield said
"Currently, phpstan complains about readonly properties that are not assigned in the constructor, or if they're assigned from elsewhere in the class.

While it's true that in many cases that's a code smell, there are also ample cases where this is entirely reasonable to do, even beneficial, and so these rules create false positives.

I believe these rules should be removed, or disable-able. (If they're already disableable and I don't see a flag for it, please advise on the flag.)"
Original issue: "#6562"

I have problems when I want do denormalize/deserialize data to my readonly DTO (request/response) classes for example using
https://symfony.com/doc/current/serializer.html#built-in-normalizers
PropertyNormalizer.php. They should not have any __construct. Would it be possible to add some "@" type annotation to disable this behavior for certain class?

Best regards Stefan

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions