3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum WeekDay: string { case Monday = 'monday'; case Tuesday = 'tuesday'; case Wednesday = 'wednesday'; case Thursday = 'thursday'; case Friday = 'friday'; case Saturday = 'saturday'; case Sunday = 'sunday'; } class Foo { public function hello() { return "Hello world" . PHP_EOL; } } $array = []; $array[WeekDay::Monday->value] = new Foo(); // etc echo $array[WeekDay::Monday->value]->hello(); $map = new WeakMap(); $map[WeekDay::Monday] = new Foo(); // etc echo $map[WeekDay::Monday]->hello();
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Hello world Hello world

preferences:
49.01 ms | 843 KiB | 4 Q