Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@Wosi
Copy link

@Wosi Wosi commented Nov 12, 2019

Copy link
Member

This needs a test, preferably inside ImpossibleCheckTypeFunctionCallRuleTest.

adaamz and Wosi reacted with thumbs up emoji

@Wosi Wosi force-pushed the fixes/1482_method_exists_with_string branch from bad1c12 to 07020b2 Compare November 12, 2019 10:32
Copy link
Author

Wosi commented Nov 12, 2019

@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?

Copy link
Member

@ondrejmirtes ondrejmirtes left a 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 :)

Copy link
Member

@ondrejmirtes ondrejmirtes Nov 12, 2019

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.

Copy link
Author

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.

Copy link
Member

@ondrejmirtes ondrejmirtes Nov 12, 2019

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.

Copy link
Author

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')

@Wosi Wosi force-pushed the fixes/1482_method_exists_with_string branch from 07020b2 to bfd7b65 Compare November 12, 2019 11:28
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /