3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface WithStaticMethod { static function foo(); } class Foo implements WithStaticMethod { public static function foo() { return __CLASS__; } } $fooClass = Foo::class; echo $fooClass::$foo();
Output for 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined variable $foo in /in/HvZAc on line 13 Fatal error: Uncaught Error: Method name must be a string in /in/HvZAc:13 Stack trace: #0 {main} thrown in /in/HvZAc on line 13
Process exited with code 255.
Output for 7.0.0
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in /in/HvZAc on line 7 Fatal error: Constructor Foo::foo() cannot be static in /in/HvZAc on line 7
Process exited with code 255.
Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.16
Fatal error: Constructor Foo::foo() cannot be static in /in/HvZAc on line 9
Process exited with code 255.

preferences:
86.78 ms | 402 KiB | 44 Q