3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function getClosure() { var_dump(self::class, static::class); return function () { }; } } class B extends A { } $b = new B(); $c = $b->getClosure(); $r = new ReflectionFunction($c); var_dump($r->getClosureThis() === $b); var_dump($r->getClosureScopeClass()); // self::class var_dump($r->getClosureCalledClass()); // static::class
Output for 8.1.11 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(1) "A" string(1) "B" bool(true) object(ReflectionClass)#4 (1) { ["name"]=> string(1) "A" } object(ReflectionClass)#4 (1) { ["name"]=> string(1) "B" }
Output for 8.1.0 - 8.1.10
string(1) "A" string(1) "B" bool(true) object(ReflectionClass)#4 (1) { ["name"]=> string(1) "A" } Fatal error: Uncaught Error: Call to undefined method ReflectionFunction::getClosureCalledClass() in /in/JOphS:21 Stack trace: #0 {main} thrown in /in/JOphS on line 21
Process exited with code 255.

preferences:
54.13 ms | 407 KiB | 5 Q