3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types = 1); /** * @template-covariant T */ final class Collection { /** * @param list<T> $items */ public function __construct( private array $items = [], ) { } /** * @template TValue * @param Closure(T, int): TValue $callback * @return Collection<TValue> */ public function map(Closure $callback): self { $mapped = []; foreach ($this->items as $key => $item) { $mapped[] = $callback($item, $key); } return new self($mapped); } } enum X: string { case CASE1 = 'case1'; case CASE2 = 'case2'; } (new Collection(['case1']))->map(X::from(...));
Output for 8.1.30 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
Fatal error: Uncaught ArgumentCountError: X::from() expects exactly 1 argument, 2 given in /in/YWSEo:25 Stack trace: #0 /in/YWSEo(25): X::from('case1', 0) #1 /in/YWSEo(37): Collection->map(Object(Closure)) #2 {main} thrown in /in/YWSEo on line 25
Process exited with code 255.

preferences:
29.16 ms | 1137 KiB | 7 Q