Skip to content

ReadWritePropertiesExtension is not respected with readonly property #6632

@noemi-salaun

Description

@noemi-salaun

Bug report

I have Doctrine entities with an $id properties that are never initialized in my code. I made PHPStan aware of it with a ReadWritePropertiesExtension and it works perfectly.

But if I add the new readonly keyword on my property, PHPStan give me this error

Class MyEntity has an uninitialized readonly property $id. Assign it in the constructor.

Code snippet that reproduces the problem

#[ORM\Entity]
class MyEntity
{
    #[ORM\Column, ORM\Id, ORM\GeneratedValue]
    private readonly int $id;

    #[ORM\Column]
    private string $name;

    public function __construct(string $name)
    {
        $this->name = $name;
    }
}

Expected output

I expect no error from PHPStan, since the extension tell it that the property is always initialized

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions