Skip to content

Class App\Entity\User has an uninitialized readonly property $id. Assign it in the constructor. #7337

@karaka200

Description

@karaka200

Bug report

Class App\Entity\User has an uninitialized readonly property $id. Assign it in the constructor.

Code snippet that reproduces the problem

I use Symfony 6.1.0 and PHP 8.1.6.My user entity has this code:

...
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private readonly int $id;
...

I install phpstan/phpstan and phpstan/phpstan-doctrine and phpstan/phpstan-symfony packages.
When analyze with PHPStan ( php vendor/bin/phpstan analyse src ), display this error:

 ------ -------------------------------------------------------------------------------------------------
  Line   Entity\User.php
 ------ -------------------------------------------------------------------------------------------------
  17     Class App\Entity\User has an uninitialized readonly property $id. Assign it in the constructor.
 ------ -------------------------------------------------------------------------------------------------

Line 17 is : private readonly int $id;

Expected output

private readonly int $id; is correct and should not display an error.

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