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

Add the sameBehaviour for offsetExists/offsetGet than isset #3323

Open
VincentLanglet opened this issue May 20, 2020 · 5 comments · May be fixed by phpstan/phpstan-src#3760
Open

Add the sameBehaviour for offsetExists/offsetGet than isset #3323

VincentLanglet opened this issue May 20, 2020 · 5 comments · May be fixed by phpstan/phpstan-src#3760

Comments

@VincentLanglet
Copy link
Contributor

Feature request

This is working
https://phpstan.org/r/1e164242-ebc4-40ca-a92e-c6c61c306bdf

This is not
https://phpstan.org/r/9ffb60c5-c6b2-460d-a2af-7708c3c70004

This is not
https://phpstan.org/r/ebbd7013-d22f-403f-bc14-6dcda8026def

All should be working the same way IMHO.

@VincentLanglet
Copy link
Contributor Author

@ondrejmirtes I wouldlike to try to implement this.

Could you explain to me how isset works with phpstan and what I should do for offsetExist/offsetGet ? :)

@ondrejmirtes
Copy link
Member

For offsetGet to work, there needs to be a dynamic return type extension that asks the type in $methodCall->var about hasOffsetValueType.

For offsetExists to work, there has to be a type-specifying extension for that method with similar logic as this one https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php.

@phpstan-bot
Copy link
Contributor

@VincentLanglet PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+6: Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
+6: Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
+6: Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
+6: Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.
Full report
Line Error
6 Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.

@phpstan-bot
Copy link
Contributor

@VincentLanglet PHPStan now reports different result with your code snippet:

@@ @@
+ 6: Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.
 14: Cannot access property $vars on FormView|null.
Full report
Line Error
6 Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.
14 `Cannot access property $vars on FormView

@phpstan-bot
Copy link
Contributor

@VincentLanglet PHPStan now reports different result with your code snippet:

@@ @@
+ 6: Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
+ 6: Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.
 14: Cannot access property $vars on FormView|null.
Full report
Line Error
6 Non-abstract class FormView contains abstract method offsetExists() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetGet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetSet() from interface ArrayAccess.
6 Non-abstract class FormView contains abstract method offsetUnset() from interface ArrayAccess.
14 `Cannot access property $vars on FormView

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

Successfully merging a pull request may close this issue.

3 participants