<?php
trait T
{
public function self(): self { return $this; }
public function parent(): parent { return $this; }
public function static(): static { return $this; }
}
$selfType = (new ReflectionMethod(T::class, 'self'))->getReturnType();
var_dump($selfType::class, $selfType->getName());
$parentType = (new ReflectionMethod(T::class, 'parent'))->getReturnType();
var_dump($parentType::class, $parentType->getName());
$staticType = (new ReflectionMethod(T::class, 'static'))->getReturnType();
var_dump($staticType::class, $staticType->getName());
final class A
{
use T;
}
$selfType = (new ReflectionMethod(A::class, 'self'))->getReturnType();
var_dump($selfType::class, $selfType->getName());
$parentType = (new ReflectionMethod(A::class, 'parent'))->getReturnType();
var_dump($parentType::class, $parentType->getName());
$staticType = (new ReflectionMethod(A::class, 'static'))->getReturnType();
var_dump($staticType::class, $staticType->getName());