Skip to content

Commit e165716

Browse files
committed
Cover get_parent_class(self::class) inside a trait
self::class is not late static bound: inside a trait it is already the using class as a constant class-string, indistinguishable from writing Bar::class, so it keeps the exact parent while $this / static::class stay conservative.
1 parent 8d3f5de commit e165716

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎tests/PHPStan/Analyser/nsrt/get-parent-class.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public function doBaz()
4949
assertType('class-string|false', get_parent_class());
5050
assertType('class-string|false', get_parent_class($this));
5151
assertType('class-string|false', get_parent_class(static::class));
52+
53+
// self::class is not late static bound - it is the using class, so it is already a
54+
// constant class-string here, indistinguishable from writing Bar::class.
55+
assertType('\'ParentClass\\\\Bar\'', self::class);
56+
assertType('\'ParentClass\\\\Foo\'', get_parent_class(self::class));
57+
assertType('\'ParentClass\\\\Foo\'', get_parent_class(Bar::class));
5258
}
5359

5460
}

0 commit comments

Comments
 (0)