3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MapIterator implements Iterator { private $f; private $inner; public function __construct($f, $inner) { $this->f = $f; $this->inner = $inner; } function rewind() { return $this->inner->rewind(); } function current() { return call_user_func($this->f, $this->inner->current()); } function key() { return $this->inner->key(); } function next() { return $this->inner->next(); } function valid() { return $this->inner->valid(); } } function iter_map($f, $iter) { return new MapIterator($f, $iter); } // example: function times_two($x) { return $x * 2; } $source = new ArrayIterator([0, 1, 2, 3, 4, 5, 6]); //var_dump(iterator_to_array(iter_map('times_two', $source))); print_r(iterator_to_array(gen_map('times_two', $source)));
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of MapIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7AgCS on line 16 Deprecated: Return type of MapIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7AgCS on line 24 Deprecated: Return type of MapIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7AgCS on line 20 Deprecated: Return type of MapIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7AgCS on line 28 Deprecated: Return type of MapIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7AgCS on line 12 Fatal error: Uncaught Error: Call to undefined function gen_map() in /in/7AgCS:46 Stack trace: #0 {main} thrown in /in/7AgCS on line 46
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:
44.7 ms | 402 KiB | 8 Q