3v4l.org

run code in 300+ PHP versions simultaneously
<?php $r= new ReflectionClass(new class() { public function instance(): self { return $this; } }); $type= $r->getMethod('instance')->getReturnType(); var_dump($type->getName()); $o = new ($type->getName()); var_dump($o);
Output for 8.2.28 - 8.2.29, 8.3.5 - 8.3.28, 8.4.5 - 8.4.15, 8.5.0
string(4) "self" Fatal error: Uncaught Error: Class "self" not found in /in/5D2aT:10 Stack trace: #0 {main} thrown in /in/5D2aT on line 10
Process exited with code 255.

preferences:
46.14 ms | 406 KiB | 5 Q