3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface BraceInitializationInterface { public static function fromElements(array $elements): static; } final class MyList implements BraceInitializationInterface { private function __construct(public readonly array $elements) {} public static function fromElements(array $elements): static { return new static(array_values($elements)); } } $list = MyList::fromElements(['a' => 'foo', 'b' => 'bar']); var_dump($list->elements);
Output for 8.1.0 - 8.1.2
array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" }
Output for 8.0.1 - 8.0.15
Parse error: syntax error, unexpected token "array", expecting variable in /in/aZqhq on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.27
Parse error: syntax error, unexpected 'static' (T_STATIC) in /in/aZqhq on line 4
Process exited with code 255.

preferences:
150.85 ms | 1399 KiB | 51 Q