3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public static function F() { return "A"; } } $c = (function() { var_dump(static::F()); })->bindTo(new A, NULL); var_dump((new \ReflectionFunction($c))->getClosureScopeClass()->name); $c(); $c = (function() { var_dump(self::F()); })->bindTo(new A, "A"); var_dump((new \ReflectionFunction($c))->getClosureScopeClass()->name); $c(); $c = (function() { var_dump(self::F()); })->bindTo(new A, NULL); var_dump((new \ReflectionFunction($c))->getClosureScopeClass()->name); $c();
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(7) "Closure" string(1) "A" string(1) "A" string(1) "A" string(7) "Closure" Fatal error: Uncaught Error: Call to undefined method Closure::F() in /in/SuAuh:13 Stack trace: #0 /in/SuAuh(15): Closure->{closure:/in/SuAuh:13}() #1 {main} thrown in /in/SuAuh on line 13
Process exited with code 255.
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30
string(7) "Closure" string(1) "A" string(1) "A" string(1) "A" string(7) "Closure" Fatal error: Uncaught Error: Call to undefined method Closure::F() in /in/SuAuh:13 Stack trace: #0 /in/SuAuh(15): Closure->{closure}() #1 {main} thrown in /in/SuAuh on line 13
Process exited with code 255.

preferences:
111.45 ms | 1290 KiB | 4 Q