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 . "!"; // OK, but unnecessary LSB } public function greetConst(string $to): string { return static::PREFIX . $to . "!"; // It should be self::PREFIX. } } class Bar extends Foo { } class Buz extends Foo { private static string $prefix = "Hi, "; private function prefix(): string { return "Hi, "; } } echo (new Bar())->greetFunc("World") . PHP_EOL; echo (new Bar())->greetVar("World") . PHP_EOL; // echo (new Bar())->greetConst("World") . PHP_EOL; // Referencing undefined Bar::PREFIX... // echo (new Buz())->greetFunc("World") . PHP_EOL; // Referencing Buz::prefix() from Foo class echo (new Buz())->greetVar("World") . PHP_EOL;
Output for git.master, git.master_jit
Hello, World! Hello, World! Fatal error: Uncaught Error: Cannot access private property Buz::$prefix in /in/gp5YU:21 Stack trace: #0 /in/gp5YU(49): Foo->greetVar('World') #1 {main} thrown in /in/gp5YU on line 21
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.94 ms | 478 KiB | 5 Q