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

Report invalid constructor property promotion for readonly props already defined in parent class constructor #8101

Closed
ZebulanStanphill opened this issue Oct 3, 2022 · 2 comments · Fixed by phpstan/phpstan-src#3049

Comments

@ZebulanStanphill
Copy link
Contributor

Feature request

Declaring a child class with constructor property promotion for a property already declared in the parent class' constructor throws a fatal error at runtime when the child class is instantiated. PHPStan does not currently report this.

https://3v4l.org/oLdjg#v8.1.11

https://phpstan.org/r/cf781e9e-cfdd-4aae-855d-ead64bf16afa

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

I saw that full support for the list type was recently introduced. Definitely looking forward to that.

@ondrejmirtes
Copy link
Member

The re-declaration is allowed, but call to parent constructor in your example fails: https://3v4l.org/jPiT7#v8.1.11

@Jurigag
Copy link

Jurigag commented Oct 6, 2022

Yea, the issue with code here that you first set it in class B via property promotion and then try to modify it via constructor of class A. You shouldn't have public readonly in first place in class B.

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

Successfully merging a pull request may close this issue.

3 participants