3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private const string PREFIX = "Hello. "; private static string $prefix = "Hello, "; private function prefix(): string { return "Hello, "; } public function greetFunc(string $to): string { return static::prefix() . $to . "!"; // OK, but unnecessary LSB } public function greetVar(string $to): string { return static::$prefix . $to . "!"; // It should be self::$prefix. } 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; // Actually using Foo::prefix() instead of Bar::prefix() echo (new Bar())->greetVar("World") . PHP_EOL; // Referencing undefined Bar::$prefix... echo (new Bar())->greetConst("World") . PHP_EOL; // Referencing undefined Bar::PREFIX...
Output for 8.3.0 - 8.3.28, 8.4.1 - 8.4.15, 8.5.0
Hello, World! Hello, World! Fatal error: Uncaught Error: Undefined constant Bar::PREFIX in /in/rZk6Z:26 Stack trace: #0 /in/rZk6Z(36): Foo->greetConst('World') #1 {main} thrown in /in/rZk6Z on line 26
Process exited with code 255.
Output for 8.2.0 - 8.2.29
Parse error: syntax error, unexpected identifier "PREFIX", expecting "=" in /in/rZk6Z on line 5
Process exited with code 255.

preferences:
47.85 ms | 407 KiB | 5 Q