Skip to content

Add the sameBehaviour for offsetExists/offsetGet than isset #3323

Open
phpstan/phpstan-src
#3760

Activity

VincentLanglet

VincentLanglet commented on Jun 2, 2020

@VincentLanglet
ContributorAuthor

@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

ondrejmirtes commented on Jun 2, 2020

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

phpstan-bot commented on Mar 9, 2021

@phpstan-bot
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

phpstan-bot commented on Mar 9, 2021

@phpstan-bot
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

phpstan-bot commented on Mar 9, 2021

@phpstan-bot
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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Participants

    @ondrejmirtes@VincentLanglet@phpstan-bot

    Issue actions

      Add the sameBehaviour for offsetExists/offsetGet than isset · Issue #3323 · phpstan/phpstan