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

Support get_parent_class() in type specifier #5552

Closed
staabm opened this issue Aug 29, 2021 · 6 comments · Fixed by phpstan/phpstan-src#1383
Closed

Support get_parent_class() in type specifier #5552

staabm opened this issue Aug 29, 2021 · 6 comments · Fixed by phpstan/phpstan-src#1383

Comments

@staabm
Copy link
Contributor

staabm commented Aug 29, 2021

Feature request

similar to phpstan/phpstan-src@df27a12

https://phpstan.org/r/ef2f0c50-62c8-480e-bfa6-cbe19dc1199a

more relevant testcases can be inspired from https://github.com/phpstan/phpstan-src/blob/579b075806f32076dfaf55a4f2c913f55ed14a5c/tests/PHPStan/Analyser/data/generic-class-string.php

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

@ondrejmirtes
Copy link
Member

Supporting anything with === has priority. I'm not a fan of ==.

@staabm
Copy link
Contributor Author

staabm commented Aug 30, 2021

Supporting anything with === has priority. I'm not a fan of ==.

ohh thats a interessting pointer. I had a look in our private codebases and also some phpstan type-specifying logic..

In our legacy world most code is still using == (or != etc) over === etc.
This will stay like this for a long time, since we cannot "just change" all these operators - and we have a lot of code.

I agree with the general statement that we should prefer === over ==, but in the same turn for my employers use-cases of phpstan I need support of ==.

I hope you are still welcoming == supporting cases...?

for this specific issue here, I would try to support == and === in a single PR.

@ondrejmirtes
Copy link
Member

The way forward is to code everything in TypeSpecifier as if it was for ===. And then have some general code that is applied if both types on left and right side of == are the same then the same logic from === will be applied to == as well.

@phpstan-bot
Copy link
Contributor

@staabm After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
- 7: Method HelloWorld::sayHello() has parameter $o with no typehint specified.
+ 7: Method HelloWorld::sayHello() has parameter $o with no type specified.
 10: Expected type A, actual: mixed
Full report
Line Error
7 Method HelloWorld::sayHello() has parameter $o with no type specified.
10 Expected type A, actual: mixed

@ondrejmirtes
Copy link
Member

Implemented by phpstan/phpstan-src#1383

@github-actions
Copy link

github-actions bot commented Nov 6, 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 Nov 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants