Skip to content

Commit 9689310

Browse files
committed
Cover @Final classes in get_parent_class()
ClassReflection::isFinal() already honours the @Final PHPDoc, so an @Final class gets no subclass widening, same as the final keyword.
1 parent e165716 commit 9689310

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎tests/PHPStan/Analyser/nsrt/bug-14951.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,32 @@ final class FinalWithParent extends A
6464
public function parentOfThis(): void
6565
{
6666
assertType("'Bug14951\\\\A'", get_parent_class($this));
67+
assertType("'Bug14951\\\\A'", get_parent_class(static::class));
68+
}
69+
70+
}
71+
72+
/** @final */
73+
class PhpDocFinalNoParent
74+
{
75+
76+
public function parentOfThis(): void
77+
{
78+
// A @final class cannot be subclassed either, so there is no subclass widening.
79+
assertType('false', get_parent_class($this));
80+
assertType('false', get_parent_class(static::class));
81+
}
82+
83+
}
84+
85+
/** @final */
86+
class PhpDocFinalWithParent extends A
87+
{
88+
89+
public function parentOfThis(): void
90+
{
91+
assertType("'Bug14951\\\\A'", get_parent_class($this));
92+
assertType("'Bug14951\\\\A'", get_parent_class(static::class));
6793
}
6894

6995
}

0 commit comments

Comments
 (0)