Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
karaka200 opened this issue May 28, 2022 · 7 comments · Fixed by phpstan/phpstan-doctrine#339
Labels

Comments

@karaka200
Copy link

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.

@mergeable
Copy link

mergeable bot commented May 28, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#1357

@karaka200
Copy link
Author

karaka200 commented May 30, 2022

@ondrejmirtes I updated the PHPStan and deleted the result cache, but I still get this errors

@ondrejmirtes
Copy link
Member

/cc @herndlm can you please verify the fix in phpstan-doctrine? Write a new RuleTestCase for the right rule and get the rule instance via self::getContained()->getByType(). And if the test passes, verify that it failed before the fix in PHPStan. Thank you 😊

@ondrejmirtes
Copy link
Member

Fixed and released in phpstan-doctrine 1.3.7. Please test it, thanks.

@karaka200
Copy link
Author

Thank you. Works without problems

@github-actions
Copy link

github-actions bot commented Jul 3, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants