Skip to content

Commit

Permalink
Access to an undefined property should be appropriate for these cases.
Browse files Browse the repository at this point in the history
Should be fixed by specifying types in isset.
Related issue phpstan/phpstan#3171
  • Loading branch information
rajyan committed Apr 21, 2022
1 parent e64bc9a commit a624060
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Rules/Properties/AccessPropertiesRule.php
Expand Up @@ -79,7 +79,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
return [];
}

if ($type->canAccessProperties()->no() || $type->canAccessProperties()->maybe() && !$this->canAccessUndefinedProperties($scope, $node)) {
if ($type->canAccessProperties()->no() || $type->canAccessProperties()->maybe() && !$scope->isUndefinedExpressionAllowed($node)) {
return [
RuleErrorBuilder::message(sprintf(
'Cannot access property $%s on %s.',
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php
Expand Up @@ -495,7 +495,7 @@ public function testAccessPropertiesOnDynamicProperties(): void
299,
],
[
'Cannot access property $foo on TestAccessProperties\PropertyIssetOnPossibleFalse|false.',
'Access to an undefined property TestAccessProperties\PropertyIssetOnPossibleFalse|false::$foo.',
315,
],
[
Expand All @@ -511,7 +511,7 @@ public function testAccessPropertiesOnDynamicProperties(): void
402,
],
[
'Cannot access property $array on stdClass|null.',
'Access to an undefined property stdClass|null::$array.',
412,
],
],
Expand Down

0 comments on commit a624060

Please sign in to comment.