phpstan: False positives when using `method_exists()` with a static method
Summary of a problem or a feature request
When using method_exists() with a static method, it is giving a false positive error. The PHP documentation clearly highlights this as a valid use-case.
Code snippet that reproduces the problem
https://phpstan.org/r/ddb2e9099834cf325a7917bcd50b42e2
Actual output
Call to an undefined static method Greetings::waveGoodbye().
Expected output
Nothing. Should have no errors
Similar to #323
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 27 (21 by maintainers)
Links to this issue
- Update dependency phpstan/phpstan to v1.9.2 (!275) · Merge requests · nano8 / core / display · GitLab
- Update dependency phpstan/phpstan to v1.9.2 (!132) · Merge requests · nano8 / core / middleware · GitLab
- Update dependency phpstan/phpstan to v1.9.2 (!216) · Merge requests · nano8 / core / security · GitLab
- Update dependency phpstan/phpstan to v1.9.2 (!239) · Merge requests · nano8 / core / request · GitLab
- Update dependency phpstan/phpstan to v1.9.2 (!236) · Merge requests · nano8 / core / validate · GitLab
- Update dependency phpstan/phpstan to v1.9.2 (!224) · Merge requests · nano8 / core / endpoints · GitLab
@josephzidell What does “bump” mean? Either send a pull request with a fix, or wait. Issue is urgent when a lot of people have the same problem, not just because one guy says “bump”.
Yes, please keep this open, a bug is still a bug.
I’m calling this from the parent class, and checking if the child class defined the method.
@keichinger Your problem is unrelated, please open a separate issue.
I may have found another example where PhpStan is complaining that a certain method doesn’t exist, though my example may be a bit extreme 😅
https://phpstan.org/r/eed4b23c-b6e7-424f-87fa-9f88ac7150e3
In this particular case, I’ve got a very generic Trait that may or may not be used within a class-inheritance. The actual code works flawlessly, it’s just that PhpStan is (rightfully) getting confused here 😄
Without knowing the internals of PhpStan, I can imagine that fixing this particular case may be an extreme case of „This code is making sure that it’s safe to call said method though
parent::doesn’t know about it” 😅Hard to decide!