3v4l.org

run code in 300+ 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 git.master_jit, git.master
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.

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:
81.68 ms | 405 KiB | 5 Q