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 self::prefix() . $to . "!"; // OK, but unnecessary LSB } public function greetVar(string $to): string { return self::$prefix . $to . "!"; // OK, but unnecessary LSB } public function greetConst(string $to): string { return static::PREFIX . $to . "!"; // It should be self::PREFIX. } } 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.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Hello, World! Hello, World! Hello, World! Hello, World!
Output for 8.1.34, 8.2.0 - 8.2.30
Parse error: syntax error, unexpected identifier "PREFIX", expecting "=" in /in/Cks3J on line 5
Process exited with code 255.

preferences:
64.24 ms | 407 KiB | 5 Q