diff --git a/src/Rules/Properties/AccessPropertiesRule.php b/src/Rules/Properties/AccessPropertiesRule.php index 7c389eff86..55d2e237f2 100644 --- a/src/Rules/Properties/AccessPropertiesRule.php +++ b/src/Rules/Properties/AccessPropertiesRule.php @@ -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.', diff --git a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php index 902127910b..1ee7b1aec8 100644 --- a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php @@ -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, ], [ @@ -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, ], ],