3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Everything you enter here will be executed by our servers. Try it! function iterator_pipeline(\Traversable $source, $steps) { $gen = $source; foreach ($steps as $step) { if (is_array($step) and !is_callable($step)) { $g = array_shift($step); array_unshift($step, $gen); if (class_exists($g)) { $class = new \ReflectionClass($className); $gen = $class->newInstanceArgs($step); } else if (is_callable($g)) { $gen = call_user_func_array($g, $step); } } else if (is_callable($step)) { $gen = $step($gen); } } return $gen; } function iterator_chunk(\Traversable $it, $chunkSize) { $it->rewind(); $chunk = []; $steps = range(1, $chunkSize); while (true) { foreach ($steps as $_) { if (!$it->valid()) { break 2; } $chunk[] = $it->current(); $it->next(); } yield $chunk; $chunk = []; } if ($chunk) { yield $chunk; } } function iterator_consume(\Traversable $it) { foreach ($it as $key => $value) {} } function iterator_pass(\Traversable $it) { foreach ($it as $key => $value) { yield $key => $value; } } $steps = [ function($it) { foreach ($it as $val) { yield chr($val); } }, "iterator_pass", ["iterator_chunk", 32], function($it) { foreach ($it as $val) { print_r($val); yield $val; } } ]; $it = iterator_pipeline(new \ArrayIterator(range(0, 127)), $steps); iterator_consume($it);
Output for 5.5.0 - 7.1.0
Array ( [0] => [1] =>  [2] =>  [3] =>  [4] =>  [5] =>  [6] =>  [7] =>  [8] =>  [9] => [10] => [11] => [12] => [13] => [14] =>  [15] =>  [16] =>  [17] =>  [18] =>  [19] =>  [20] =>  [21] =>  [22] =>  [23] =>  [24] =>  [25] =>  [26] =>  [27] =>  [28] =>  [29] =>  [30] =>  [31] =>  ) Array ( [0] => [1] => ! [2] => " [3] => # [4] => $ [5] => % [6] => & [7] => ' [8] => ( [9] => ) [10] => * [11] => + [12] => , [13] => - [14] => . [15] => / [16] => 0 [17] => 1 [18] => 2 [19] => 3 [20] => 4 [21] => 5 [22] => 6 [23] => 7 [24] => 8 [25] => 9 [26] => : [27] => ; [28] => < [29] => = [30] => > [31] => ? ) Array ( [0] => @ [1] => A [2] => B [3] => C [4] => D [5] => E [6] => F [7] => G [8] => H [9] => I [10] => J [11] => K [12] => L [13] => M [14] => N [15] => O [16] => P [17] => Q [18] => R [19] => S [20] => T [21] => U [22] => V [23] => W [24] => X [25] => Y [26] => Z [27] => [ [28] => \ [29] => ] [30] => ^ [31] => _ ) Array ( [0] => ` [1] => a [2] => b [3] => c [4] => d [5] => e [6] => f [7] => g [8] => h [9] => i [10] => j [11] => k [12] => l [13] => m [14] => n [15] => o [16] => p [17] => q [18] => r [19] => s [20] => t [21] => u [22] => v [23] => w [24] => x [25] => y [26] => z [27] => { [28] => | [29] => } [30] => ~ [31] =>  )
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/UXdgQ on line 43
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/UXdgQ on line 30
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 27 Parse error: syntax error, unexpected '[' in /in/UXdgQ on line 30
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 27 Parse error: parse error, unexpected '[' in /in/UXdgQ on line 30
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 4 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/UXdgQ on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 4 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/UXdgQ on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/UXdgQ on line 4 Parse error: parse error, expecting `')'' in /in/UXdgQ on line 4
Process exited with code 255.