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 ($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 = [ ["iterator_chunk", 32], function($it) { foreach ($it as $val) { yield chr($val); } }, ]; $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 ====== '' . "\0" . '' ====== Chunk 1 ====== '' ====== Chunk 2 ====== '' ====== Chunk 3 ====== '' ====== Chunk 4 ====== '' ====== Chunk 5 ====== '' ====== Chunk 6 ====== '' ====== Chunk 7 ====== '' ====== Chunk 8 ====== '' ====== Chunk 9 ====== ' ' ====== Chunk 10 ====== ' ' ====== Chunk 11 ====== ' ' ====== Chunk 12 ====== ' ' ====== Chunk 13 ====== ' ' ====== Chunk 14 ====== '' ====== Chunk 15 ====== '' ====== Chunk 16 ====== '' ====== Chunk 17 ====== '' ====== Chunk 18 ====== '' ====== Chunk 19 ====== '' ====== Chunk 20 ====== '' ====== Chunk 21 ====== '' ====== Chunk 22 ====== '' ====== Chunk 23 ====== '' ====== Chunk 24 ====== '' ====== Chunk 25 ====== '' ====== Chunk 26 ====== '' ====== Chunk 27 ====== '' ====== Chunk 28 ====== '' ====== Chunk 29 ====== '' ====== Chunk 30 ====== '' ====== Chunk 31 ====== '' ====== Chunk 32 ====== ' ' ====== Chunk 33 ====== '!' ====== Chunk 34 ====== '"' ====== Chunk 35 ====== '#' ====== Chunk 36 ====== '$' ====== Chunk 37 ====== '%' ====== Chunk 38 ====== '&' ====== Chunk 39 ====== '\'' ====== Chunk 40 ====== '(' ====== Chunk 41 ====== ')' ====== Chunk 42 ====== '*' ====== Chunk 43 ====== '+' ====== Chunk 44 ====== ',' ====== Chunk 45 ====== '-' ====== Chunk 46 ====== '.' ====== Chunk 47 ====== '/' ====== Chunk 48 ====== '0' ====== Chunk 49 ====== '1' ====== Chunk 50 ====== '2' ====== Chunk 51 ====== '3' ====== Chunk 52 ====== '4' ====== Chunk 53 ====== '5' ====== Chunk 54 ====== '6' ====== Chunk 55 ====== '7' ====== Chunk 56 ====== '8' ====== Chunk 57 ====== '9' ====== Chunk 58 ====== ':' ====== Chunk 59 ====== ';' ====== Chunk 60 ====== '<' ====== Chunk 61 ====== '=' ====== Chunk 62 ====== '>' ====== Chunk 63 ====== '?' ====== Chunk 64 ====== '@' ====== Chunk 65 ====== 'A' ====== Chunk 66 ====== 'B' ====== Chunk 67 ====== 'C' ====== Chunk 68 ====== 'D' ====== Chunk 69 ====== 'E' ====== Chunk 70 ====== 'F' ====== Chunk 71 ====== 'G' ====== Chunk 72 ====== 'H' ====== Chunk 73 ====== 'I' ====== Chunk 74 ====== 'J' ====== Chunk 75 ====== 'K' ====== Chunk 76 ====== 'L' ====== Chunk 77 ====== 'M' ====== Chunk 78 ====== 'N' ====== Chunk 79 ====== 'O' ====== Chunk 80 ====== 'P' ====== Chunk 81 ====== 'Q' ====== Chunk 82 ====== 'R' ====== Chunk 83 ====== 'S' ====== Chunk 84 ====== 'T' ====== Chunk 85 ====== 'U' ====== Chunk 86 ====== 'V' ====== Chunk 87 ====== 'W' ====== Chunk 88 ====== 'X' ====== Chunk 89 ====== 'Y' ====== Chunk 90 ====== 'Z' ====== Chunk 91 ====== '[' ====== Chunk 92 ====== '\\' ====== Chunk 93 ====== ']' ====== Chunk 94 ====== '^' ====== Chunk 95 ====== '_' ====== Chunk 96 ====== '`' ====== Chunk 97 ====== 'a' ====== Chunk 98 ====== 'b' ====== Chunk 99 ====== 'c' ====== Chunk 100 ====== 'd' ====== Chunk 101 ====== 'e' ====== Chunk 102 ====== 'f' ====== Chunk 103 ====== 'g' ====== Chunk 104 ====== 'h' ====== Chunk 105 ====== 'i' ====== Chunk 106 ====== 'j' ====== Chunk 107 ====== 'k' ====== Chunk 108 ====== 'l' ====== Chunk 109 ====== 'm' ====== Chunk 110 ====== 'n' ====== Chunk 111 ====== 'o' ====== Chunk 112 ====== 'p' ====== Chunk 113 ====== 'q' ====== Chunk 114 ====== 'r' ====== Chunk 115 ====== 's' ====== Chunk 116 ====== 't' ====== Chunk 117 ====== 'u' ====== Chunk 118 ====== 'v' ====== Chunk 119 ====== 'w' ====== Chunk 120 ====== 'x' ====== Chunk 121 ====== 'y' ====== Chunk 122 ====== 'z' ====== Chunk 123 ====== '{' ====== Chunk 124 ====== '|' ====== Chunk 125 ====== '}' ====== Chunk 126 ====== '~' ====== Chunk 127 ====== ''
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$chunk' (T_VARIABLE) in /in/Cn0rL on line 43
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Cn0rL 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/Cn0rL on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Cn0rL on line 27 Parse error: syntax error, unexpected '[' in /in/Cn0rL 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/Cn0rL on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Cn0rL on line 27 Parse error: parse error, unexpected '[' in /in/Cn0rL 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/Cn0rL on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Cn0rL on line 27 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/Cn0rL 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/Cn0rL on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Cn0rL on line 27 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/Cn0rL 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/Cn0rL on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Cn0rL on line 27 Parse error: parse error, expecting `')'' in /in/Cn0rL on line 27
Process exited with code 255.