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
Bleeding Edge: Type xxx of property xxx is not the same as type xxx of overridden property #5494
Comments
Hi, this is expected. Property types can't be covariant/contravariant - they're invariant. This helps you to be protected against the parent class writing something that isn't You can fix this issue with stub files: https://phpstan.org/user-guide/stub-files |
In that case, how am I supposed to overwrite third-party library code that expects me to overwrite it but is not phpstan-compatible? I can't - at least not without StubFiles as it seems. But instead, I and probably many others will just write |
Yeah, I'll relax those rules a bit, same as method parameters and return types are not enforced fully by default. The strictest variant will be an opt-in via a separate option (and enabled in phpstan-strict-rules). |
Implemented: phpstan/phpstan-src@24f6264 The rules are relaxed a bit, you should get the stricter version with There are also included tips in the error messages telling you about this option and stub files. |
Thank you very much! |
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. |
Bug report
I get the error
with bleeding-edge enabled. Link to the Playground.
I'm overriding the property of the lumen error handler so I can't change the parent class. But IMO, since I'm making the type more concrete, this shouldn't be an error in the first place.
Expected output
No error, as we make the type more concrete than it is.
The text was updated successfully, but these errors were encountered: