3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function chain($iterable, array $functions) { foreach ($functions as $function) { $iterable = $function(as_iterator($iterable)); } } function as_iterator($iterable) { if ($iterable instanceof \Iterator) { return $iterable; } if (is_array($iterable)) { return new \ArrayIterator($iterable); } if (is_string($iterable)) { return new \ArrayIterator(str_split($iterable)); } throw new \Exception(); } function do_map(callable $function) { return function(Iterator $iterator) use ($function) { foreach ($iterator as $key => $value) { yield $key => $value; } }; } function do_filter(callable $function) { return function(Iterator $iterator) use($function) { foreach ($iterator as $key => $value) { if ($function($value, $key)) { yield $key => $value; } } }; } function do_concat($iterable) { return function(Iterator $iterator) use ($iterable) { foreach ($iterator as $value) { yield $value; } foreach (as_iterator($iterable) as $value) { yield $value; } }; } function do_as_array() { return function(Iterator $iterator) { return iterator_to_array($iterator); }; } $array = chain([1, 2, 3, 4], [ do_concat([5, 6, 7, 8]), do_filter(function ($v) { return $v % 2 == 0; }), do_map(function ($v) { return $v * 3; }), do_as_array(), ]);
Output for 5.5.24 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/SeSbN on line 28
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/SeSbN on line 28
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SeSbN on line 12 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SeSbN on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SeSbN on line 19 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SeSbN on line 21 Parse error: syntax error, unexpected T_FUNCTION in /in/SeSbN on line 26
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/SeSbN on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/SeSbN 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_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/SeSbN on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'&'' or `T_VARIABLE' or `T_CONST' in /in/SeSbN on line 3
Process exited with code 255.