-
Notifications
You must be signed in to change notification settings - Fork 545
Fix #1482: method_exists() with string #12
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
Fix #1482: method_exists() with string #12
Conversation
This needs a test, preferably inside ImpossibleCheckTypeFunctionCallRuleTest.
bad1c12 to
07020b2
Compare
@ondrejmirtes
I added a call to method_exists with a string variable as first parameter in check-type-function-call.php and don't expect to see an error for this line.
Is it OK this way?
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.
Yes, the test is fine :)
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.
Try (new StringType())->isSuperTypeOf($objectType)->yes() instead. This will also account for unions of constant strings and is generally better.
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.
If I do this then a call like this method_exists(MethodExists::class, 'undefinedMethod') will no longer produce the error
Call to function method_exists() with 'CheckTypeFunctionCa...' and 'undefinedMethod' will always evaluate to false.
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.
Yeah, that's correct. Please write another test for that. See phpstan/phpstan#1267 it's also reported.
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.
I'm not sure if I got you right. I changed the type check according to your request and removed the expected errors for this call:
method_exists(MethodExists::class, 'undefinedMethod')
07020b2 to
bfd7b65
Compare
Thanks!
Solves phpstan/phpstan#1482