3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 7.0.0 - 7.1.0
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.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: Class already declared: MapIterator in /in/7AgCS:3 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: Class already declared: MapIterator in /in/7AgCS on line 3
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Call to undefined function gen_map() in /in/7AgCS on line 46
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/7AgCS on line 43
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ')' in /in/7AgCS on line 43
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/7AgCS on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/7AgCS on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/7AgCS on line 3
Process exited with code 255.