3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public static function instantiate() { return new static; } } class Bar extends Foo { public static function getName() { return 'Foo'; } } var_dump( Bar::instantiate() ); var_dump( $foo = new (Bar::getName()) );
Output for 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.6
object(Bar)#1 (0) { } object(Foo)#1 (0) { }
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.25
Parse error: syntax error, unexpected '(' in /in/5HYZ9 on line 19
Process exited with code 255.

preferences:
116.51 ms | 402 KiB | 82 Q