Skip to content

Commit

Permalink
Fix internal error for dynamic properties defined on interface on PHP…
Browse files Browse the repository at this point in the history
… 8.2
  • Loading branch information
ondrejmirtes committed Dec 17, 2022
1 parent 0476903 commit 4025209
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
39 changes: 39 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8537.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Bug8537;

/**
* @property int $x
*/
interface SampleInterface
{
}

class Sample implements SampleInterface
{
/** @param array<string,mixed> $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;
};

0 comments on commit 4025209

Please sign in to comment.