3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! function iterator_compose() { foreach (array_reverse(func_get_args()) as $it) { if (is_callable($it)) { $prev = $it; } } } function iterator_chunk($it, $chunkSize) { $chunk = []; $steps = range(0, $chunkSize); while (true) { foreach ($steps as $_) { $chunk[] = $it->current(); $it->next(); if (!$it->valid()) { break 1; } } yield $chunk; $chunk = []; } if ($chunk) { yield $chunk; } } foreach (iterator_chunk(range(0, 125), 32) as $i => $c) { echo "====== Chunk $i ======\n"; var_export($c); echo "\n"; }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 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.7
Fatal error: Uncaught Error: Call to a member function current() on array in /in/l88tL:20 Stack trace: #0 /in/l88tL(37): iterator_chunk(Array, 32) #1 {main} thrown in /in/l88tL on line 20
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Fatal error: Call to a member function current() on array in /in/l88tL on line 20
Process exited with code 255.
Output for 5.5.0 - 5.5.35
Fatal error: Call to a member function current() on a non-object in /in/l88tL on line 20
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/l88tL on line 28
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/l88tL on line 15
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, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/l88tL on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/l88tL on line 15
Process exited with code 255.

preferences:
253.63 ms | 401 KiB | 376 Q