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($source, $steps) { foreach (array_reverse($steps) as $step) { $gen = $source; 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; } } $steps = [ function($it) { foreach ($it as $val) { yield ord($val); } }, ["iterator_chunk", 32], ]; $it = iterator_compose(new \ArrayIterator(range(0, 127)), $steps); foreach ($it as $i => $c) { echo "====== Chunk $i ======\n"; var_export($c); echo "\n"; }
Output for 5.5.0 - 7.1.0
====== Chunk 0 ====== 48 ====== Chunk 1 ====== 49 ====== Chunk 2 ====== 50 ====== Chunk 3 ====== 51 ====== Chunk 4 ====== 52 ====== Chunk 5 ====== 53 ====== Chunk 6 ====== 54 ====== Chunk 7 ====== 55 ====== Chunk 8 ====== 56 ====== Chunk 9 ====== 57 ====== Chunk 10 ====== 49 ====== Chunk 11 ====== 49 ====== Chunk 12 ====== 49 ====== Chunk 13 ====== 49 ====== Chunk 14 ====== 49 ====== Chunk 15 ====== 49 ====== Chunk 16 ====== 49 ====== Chunk 17 ====== 49 ====== Chunk 18 ====== 49 ====== Chunk 19 ====== 49 ====== Chunk 20 ====== 50 ====== Chunk 21 ====== 50 ====== Chunk 22 ====== 50 ====== Chunk 23 ====== 50 ====== Chunk 24 ====== 50 ====== Chunk 25 ====== 50 ====== Chunk 26 ====== 50 ====== Chunk 27 ====== 50 ====== Chunk 28 ====== 50 ====== Chunk 29 ====== 50 ====== Chunk 30 ====== 51 ====== Chunk 31 ====== 51 ====== Chunk 32 ====== 51 ====== Chunk 33 ====== 51 ====== Chunk 34 ====== 51 ====== Chunk 35 ====== 51 ====== Chunk 36 ====== 51 ====== Chunk 37 ====== 51 ====== Chunk 38 ====== 51 ====== Chunk 39 ====== 51 ====== Chunk 40 ====== 52 ====== Chunk 41 ====== 52 ====== Chunk 42 ====== 52 ====== Chunk 43 ====== 52 ====== Chunk 44 ====== 52 ====== Chunk 45 ====== 52 ====== Chunk 46 ====== 52 ====== Chunk 47 ====== 52 ====== Chunk 48 ====== 52 ====== Chunk 49 ====== 52 ====== Chunk 50 ====== 53 ====== Chunk 51 ====== 53 ====== Chunk 52 ====== 53 ====== Chunk 53 ====== 53 ====== Chunk 54 ====== 53 ====== Chunk 55 ====== 53 ====== Chunk 56 ====== 53 ====== Chunk 57 ====== 53 ====== Chunk 58 ====== 53 ====== Chunk 59 ====== 53 ====== Chunk 60 ====== 54 ====== Chunk 61 ====== 54 ====== Chunk 62 ====== 54 ====== Chunk 63 ====== 54 ====== Chunk 64 ====== 54 ====== Chunk 65 ====== 54 ====== Chunk 66 ====== 54 ====== Chunk 67 ====== 54 ====== Chunk 68 ====== 54 ====== Chunk 69 ====== 54 ====== Chunk 70 ====== 55 ====== Chunk 71 ====== 55 ====== Chunk 72 ====== 55 ====== Chunk 73 ====== 55 ====== Chunk 74 ====== 55 ====== Chunk 75 ====== 55 ====== Chunk 76 ====== 55 ====== Chunk 77 ====== 55 ====== Chunk 78 ====== 55 ====== Chunk 79 ====== 55 ====== Chunk 80 ====== 56 ====== Chunk 81 ====== 56 ====== Chunk 82 ====== 56 ====== Chunk 83 ====== 56 ====== Chunk 84 ====== 56 ====== Chunk 85 ====== 56 ====== Chunk 86 ====== 56 ====== Chunk 87 ====== 56 ====== Chunk 88 ====== 56 ====== Chunk 89 ====== 56 ====== Chunk 90 ====== 57 ====== Chunk 91 ====== 57 ====== Chunk 92 ====== 57 ====== Chunk 93 ====== 57 ====== Chunk 94 ====== 57 ====== Chunk 95 ====== 57 ====== Chunk 96 ====== 57 ====== Chunk 97 ====== 57 ====== Chunk 98 ====== 57 ====== Chunk 99 ====== 57 ====== Chunk 100 ====== 49 ====== Chunk 101 ====== 49 ====== Chunk 102 ====== 49 ====== Chunk 103 ====== 49 ====== Chunk 104 ====== 49 ====== Chunk 105 ====== 49 ====== Chunk 106 ====== 49 ====== Chunk 107 ====== 49 ====== Chunk 108 ====== 49 ====== Chunk 109 ====== 49 ====== Chunk 110 ====== 49 ====== Chunk 111 ====== 49 ====== Chunk 112 ====== 49 ====== Chunk 113 ====== 49 ====== Chunk 114 ====== 49 ====== Chunk 115 ====== 49 ====== Chunk 116 ====== 49 ====== Chunk 117 ====== 49 ====== Chunk 118 ====== 49 ====== Chunk 119 ====== 49 ====== Chunk 120 ====== 49 ====== Chunk 121 ====== 49 ====== Chunk 122 ====== 49 ====== Chunk 123 ====== 49 ====== Chunk 124 ====== 49 ====== Chunk 125 ====== 49 ====== Chunk 126 ====== 49 ====== Chunk 127 ====== 49
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/roLqZ on line 43
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/roLqZ 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/roLqZ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 27 Parse error: syntax error, unexpected '[' in /in/roLqZ 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/roLqZ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 27 Parse error: parse error, unexpected '[' in /in/roLqZ 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/roLqZ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 27 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/roLqZ on line 27
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/roLqZ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 27 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/roLqZ on line 27
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/roLqZ on line 27 Parse error: parse error, expecting `')'' in /in/roLqZ on line 27
Process exited with code 255.