3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // thanks to metaultralurker on reddit for inspiration function call(callable $fn) { return $fn(); } function map(callable $fn, \Traversable $data) { return call(function () use ($fn, $data) { foreach ($data as $v) { yield $fn($v); } }); } function filter(callable $fn, \Traversable $data) { return call(function () use ($fn, $data) { foreach ($data as $v) { if ($fn($v)) { yield $v; } } }); } $isNotZ = function ($x) { return $x !== 'Z'; }; $data = filter($isNotZ, map('strtoupper', call(function () { foreach (range('a', 'z') as $char) { yield $char; } }))); var_dump($data->current()); $data->next(); var_dump($data->current()); $data->next(); var_dump(iterator_to_array($data));
Output for 7.0.0 - 7.1.0
string(1) "A" string(1) "B" Fatal error: Uncaught Exception: Cannot rewind a generator that was already run in /in/MSoU3:44 Stack trace: #0 /in/MSoU3(44): iterator_to_array(Object(Generator)) #1 {main} thrown in /in/MSoU3 on line 44
Process exited with code 255.
Output for hhvm-3.12.0
string(1) "A" string(1) "B" array(23) { [2]=> string(1) "C" [3]=> string(1) "D" [4]=> string(1) "E" [5]=> string(1) "F" [6]=> string(1) "G" [7]=> string(1) "H" [8]=> string(1) "I" [9]=> string(1) "J" [10]=> string(1) "K" [11]=> string(1) "L" [12]=> string(1) "M" [13]=> string(1) "N" [14]=> string(1) "O" [15]=> string(1) "P" [16]=> string(1) "Q" [17]=> string(1) "R" [18]=> string(1) "S" [19]=> string(1) "T" [20]=> string(1) "U" [21]=> string(1) "V" [22]=> string(1) "W" [23]=> string(1) "X" [24]=> string(1) "Y" }
Output for hhvm-3.10.0
Fatal error: Uncaught exception 'Exception' with message 'Need to call next() first' in /in/MSoU3:38 Stack trace: #0 /in/MSoU3(38): Generator->current() #1 {main}
Process exited with code 255.
Output for 5.5.24 - 5.6.28
string(1) "A" string(1) "B" Fatal error: Uncaught exception 'Exception' with message 'Cannot rewind a generator that was already run' in /in/MSoU3:44 Stack trace: #0 /in/MSoU3(44): iterator_to_array(Object(Generator)) #1 {main} thrown in /in/MSoU3 on line 44
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$fn' (T_VARIABLE) in /in/MSoU3 on line 12
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/MSoU3 on line 12
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MSoU3 on line 9 Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/MSoU3 on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/MSoU3 on line 9 Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/MSoU3 on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/MSoU3 on line 5
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/MSoU3 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/MSoU3 on line 5
Process exited with code 255.