3v4l.org

run code in 300+ PHP versions simultaneously
<?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());

preferences:
29.03 ms | 404 KiB | 5 Q