3v4l.org

run code in 300+ PHP versions simultaneously
<?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 $val * 2; } }, "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 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [0] => 0 [1] => 2 [2] => 4 [3] => 6 [4] => 8 [5] => 10 [6] => 12 [7] => 14 [8] => 16 [9] => 18 [10] => 20 [11] => 22 [12] => 24 [13] => 26 [14] => 28 [15] => 30 [16] => 32 [17] => 34 [18] => 36 [19] => 38 [20] => 40 [21] => 42 [22] => 44 [23] => 46 [24] => 48 [25] => 50 [26] => 52 [27] => 54 [28] => 56 [29] => 58 [30] => 60 [31] => 62 ) Array ( [0] => 64 [1] => 66 [2] => 68 [3] => 70 [4] => 72 [5] => 74 [6] => 76 [7] => 78 [8] => 80 [9] => 82 [10] => 84 [11] => 86 [12] => 88 [13] => 90 [14] => 92 [15] => 94 [16] => 96 [17] => 98 [18] => 100 [19] => 102 [20] => 104 [21] => 106 [22] => 108 [23] => 110 [24] => 112 [25] => 114 [26] => 116 [27] => 118 [28] => 120 [29] => 122 [30] => 124 [31] => 126 ) Array ( [0] => 128 [1] => 130 [2] => 132 [3] => 134 [4] => 136 [5] => 138 [6] => 140 [7] => 142 [8] => 144 [9] => 146 [10] => 148 [11] => 150 [12] => 152 [13] => 154 [14] => 156 [15] => 158 [16] => 160 [17] => 162 [18] => 164 [19] => 166 [20] => 168 [21] => 170 [22] => 172 [23] => 174 [24] => 176 [25] => 178 [26] => 180 [27] => 182 [28] => 184 [29] => 186 [30] => 188 [31] => 190 ) Array ( [0] => 192 [1] => 194 [2] => 196 [3] => 198 [4] => 200 [5] => 202 [6] => 204 [7] => 206 [8] => 208 [9] => 210 [10] => 212 [11] => 214 [12] => 216 [13] => 218 [14] => 220 [15] => 222 [16] => 224 [17] => 226 [18] => 228 [19] => 230 [20] => 232 [21] => 234 [22] => 236 [23] => 238 [24] => 240 [25] => 242 [26] => 244 [27] => 246 [28] => 248 [29] => 250 [30] => 252 [31] => 254 )
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/t9M1J on line 43
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/t9M1J on line 30
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 27 Parse error: syntax error, unexpected '[' in /in/t9M1J 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/t9M1J on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 27 Parse error: parse error, unexpected '[' in /in/t9M1J 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/t9M1J on line 4 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/t9M1J on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/t9M1J on line 4 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/t9M1J 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/t9M1J on line 4 Parse error: parse error, expecting `')'' in /in/t9M1J on line 4
Process exited with code 255.

preferences:
285.48 ms | 401 KiB | 370 Q