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_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.1.0
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 hhvm-3.12.0
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function current() on a non-object (array)' in /in/l88tL:20 Stack trace: #0 (): iterator_chunk() #1 /in/l88tL(41): Generator->rewind() #2 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function current() on a non-object (array)' in /in/l88tL:20 Stack trace: #0 (): iterator_chunk() #1 (): Generator->next() #2 /in/l88tL(41): Generator->rewind() #3 {main}
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.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.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.