diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 789806187b..0f49698e22 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -181,7 +181,7 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember $ancestor = $this->getAncestorWithClassName($property->getDeclaringClass()->getName()); $resolvedClassReflection = null; - if ($ancestor !== null) { + if ($ancestor !== null && $ancestor->hasProperty($propertyName)->yes()) { $resolvedClassReflection = $ancestor->getClassReflection(); if ($ancestor !== $this) { $property = $ancestor->getUnresolvedPropertyPrototype($propertyName, $scope)->getNakedProperty(); diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 85fa14a9ca..dbddecc2cb 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1075,6 +1075,12 @@ public function testBug8503(): void $this->assertNoErrors($errors); } + public function testBug8537(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-8537.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/bug-8537.php b/tests/PHPStan/Analyser/data/bug-8537.php new file mode 100644 index 0000000000..d0c1a0729f --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-8537.php @@ -0,0 +1,39 @@ + $data */ + public function __construct(private array $data = []) + { + } + + public function __set(string $key, mixed $value): void + { + $this->data[$key] = $value; + } + + public function __get(string $key): mixed + { + return $this->data[$key] ?? null; + } + + public function __isset(string $key): bool + { + return array_key_exists($key, $this->data); + } +} + +function (): void { + $test = new Sample(); + $test->x = 3; + echo $test->x; +};