-
Notifications
You must be signed in to change notification settings - Fork 519
Prevent false positive on method_exists()
and function_exists()
#2277
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
base: 1.10.x
Are you sure you want to change the base?
Conversation
Maybe there should be a config switch to enable/disable this rule for function/method_exists? |
This pull request has been marked as ready for review. |
if ($functionReflection instanceof NativeFunctionReflection) { | ||
// native functions existance depends php configuration, | ||
// therefore don't judge them regarding will always exist or not | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me propose to not judge about "always exist yes/no", when function_exists()
is called on a php-src native/php-extension function - these functions might not exist at runtime and code trying to detect such optional dependency should not get flagged IMO.
wdyt?
going one step further I think it might also make sense to prevent the "always exists yes/no" error for method_exists()
, when the class involved is located in the composer vendor/ folder.
the assumption would be that the current project might support different versions of a external dependency and therefore needs to feauture detect the existance of methods.
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes do you have a opinion on the above comment?
f98d66a
to
e75395a
Compare
Should this also account for |
Pre-existing tests have different expectations regarding the "is always true/false" results, then what was discussed in the linked issue.
I wonder when/how we should/can differentiate whether we expect this "is always true/false" error or not.
I just did the trivial version, so we can see how this violates existing expectations and start discussion/feedback from here.
closes phpstan/phpstan#8980