3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private const string PREFIX = "Hello. "; private static string $prefix = "Hello, "; private static function prefix(): string { return "Hello, "; } public function greetFunc(string $to): string { return static::prefix() . $to . "!"; // passes, but insecure } public function greetVar(string $to): string { return statics::$prefix . $to . "!"; // passes, but insecure } public function greetConst(string $to): string { return static::PREFIX . $to . "!"; // crashes immediately } } class Bar extends Foo { } echo (new Bar())->greetFunc("World") . PHP_EOL; echo (new Bar())->greetVar("World") . PHP_EOL; // echo (new Bar())->greetConst("World") . PHP_EOL; // Error! Referencing undefined Bar::PREFIX... class Buz extends Foo { protected static string $prefix = "Hi, "; protected static function prefix(): string { return "Hi, "; } } echo (new Buz())->greetFunc("World") . PHP_EOL; // No! private function was actually overridden!! echo (new Buz())->greetVar("World") . PHP_EOL; // No! private property was actually overridden!!
Output for 8.3.0 - 8.3.28, 8.4.1 - 8.4.15, 8.5.0
Hello, World! Fatal error: Uncaught Error: Class "statics" not found in /in/luae4:21 Stack trace: #0 /in/luae4(35): Foo->greetVar('World') #1 {main} thrown in /in/luae4 on line 21
Process exited with code 255.
Output for 8.2.0 - 8.2.29
Parse error: syntax error, unexpected identifier "PREFIX", expecting "=" in /in/luae4 on line 5
Process exited with code 255.

preferences:
48.89 ms | 407 KiB | 5 Q