Skip to content

False positive "Access to an uninitialized readonly property" #10048

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

Closed
PsyonixDan opened this issue Oct 23, 2023 · 0 comments · Fixed by phpstan/phpstan-src#3930
Closed

False positive "Access to an uninitialized readonly property" #10048

PsyonixDan opened this issue Oct 23, 2023 · 0 comments · Fixed by phpstan/phpstan-src#3930
Labels
Milestone

Comments

@PsyonixDan
Copy link

Bug report

This specific false positive happens if a constructor creates a callback/closure, and that closure calls a method which accesses the readonly property.

These are the full requirements for the bug to be seen:

  • A class has a readonly property.
  • The property is set in the constructor.
  • A method accesses that property.
  • A callback/closure which calls the method is created in the constructor.

This bug started with version 1.10.23 and is still being reported with the latest version. The error isn't reported in earlier versions.

Code snippet that reproduces the problem

https://phpstan.org/r/9590d157-89fd-4d1f-8290-a7af4f82d461

Expected output

PHP shouldn't report an error.

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

PHPStan has been a huge help, it's great at finding bugs as part of our CICD system!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants