3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct() {} } function __new(string $class) { return (fn (...$args) => new $class(...$args))(...); } # $cb = Foo::__construct(...); # $cb = [new Foo, '__construct'](...); # $cb = __new(Foo::class)(...); $cb = __new(Foo::class); var_dump($cb());
Output for 8.1.0 - 8.1.34, 8.2.22 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.18, 8.5.0 - 8.5.3
object(Foo)#2 (0) { }
Output for 8.4.15
/bin/php-8.4.15: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory
Process exited with code 127.
Output for 8.0.0 - 8.0.13
Parse error: syntax error, unexpected token ")" in /in/RdChA on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.27
Parse error: syntax error, unexpected ')' in /in/RdChA on line 8
Process exited with code 255.
Output for 7.3.13 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/RdChA on line 8
Process exited with code 255.

preferences:
55.02 ms | 977 KiB | 4 Q