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(\Traversable $it, $chunkSize) { $it = $it->rewind(); $chunk = []; $steps = range(0, $chunkSize); while (true) { foreach ($steps as $_) { if (!$it->valid()) { break 2; } $chunk[] = $it->current(); $it->next(); } yield $chunk; $chunk = []; } if ($chunk) { yield $chunk; } } $it = new ArrayIterator(range(0, 125)); foreach (iterator_chunk($it, 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 valid() on null in /in/KdI1n:21 Stack trace: #0 /in/KdI1n(40): iterator_chunk(NULL, 32) #1 {main} thrown in /in/KdI1n on line 21
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function valid() on a non-object (null)' in /in/KdI1n:21 Stack trace: #0 (): iterator_chunk() #1 /in/KdI1n(44): 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 valid() on a non-object (null)' in /in/KdI1n:21 Stack trace: #0 (): iterator_chunk() #1 (): Generator->next() #2 /in/KdI1n(44): Generator->rewind() #3 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Fatal error: Call to a member function valid() on null in /in/KdI1n on line 21
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Fatal error: Call to a member function valid() on a non-object in /in/KdI1n on line 21
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/KdI1n on line 29
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/KdI1n on line 16
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/KdI1n on line 13 Parse error: syntax error, unexpected '[' in /in/KdI1n on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/KdI1n on line 13 Parse error: parse error, unexpected '[' in /in/KdI1n on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/KdI1n on line 13 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/KdI1n on line 13
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/KdI1n on line 13 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/KdI1n on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/KdI1n on line 13 Parse error: parse error, expecting `')'' in /in/KdI1n on line 13
Process exited with code 255.