3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://github.com/bootgly/bootgly/blob/c54e0d585869dca734d301000cee79401640e749/Bootgly/CLI/Terminal/Output/Text.php#L329-L336 // https://github.com/bootgly/bootgly/blob/c54e0d585869dca734d301000cee79401640e749/Bootgly/ABI/Configs/Set.php#L14-L26 enum Colors : int { public function __call(string $name, array $arguments) { static $value; return match ($name) { 'get' => $value ?? $this, // $this->value; 'set' => $value = $this, // $this->value = $this; // @ PHP team: Why readonly here??? default => $this }; } case Default = 1; case Bright = 2; } function printSomething(Colors $colors, string $message): void { echo sprintf("I will print %s in %s colors\n", $message, $colors->get()->name); } Colors::Default->set(); printSomething(Colors::Bright, 'Hello World'); Colors::Bright->set(); printSomething(Colors::Default, 'Hello World');
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.5 - 8.3.25, 8.4.1 - 8.4.12
I will print Hello World in Default colors I will print Hello World in Bright colors
Output for 8.0.1 - 8.0.30
Parse error: syntax error, unexpected identifier "Colors" in /in/msluq on line 6
Process exited with code 255.

preferences:
76.63 ms | 407 KiB | 5 Q