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(\Traversable $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 = [ function($it) { foreach ($it as $val) { echo "Value: $val\n"; yield $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"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 28
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/h3t39
function name:  (null)
number of ops:  30
compiled vars:  !0 = $steps, !1 = $it, !2 = $c, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fh3t39%3A53%240'
   58     1        INIT_ARRAY                                       ~5      ~4
   53     2        ADD_ARRAY_ELEMENT                                ~5      <array>
   52     3        ASSIGN                                                   !0, ~5
   62     4        INIT_FCALL                                               'iterator_compose'
          5        NEW                                              $7      'ArrayIterator'
          6        INIT_FCALL                                               'range'
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 127
          9        DO_ICALL                                         $8      
         10        SEND_VAR_NO_REF_EX                                       $8
         11        DO_FCALL                                      0          
         12        SEND_VAR                                                 $7
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !1, $10
   64    16      > FE_RESET_R                                       $12     !1, ->28
         17    > > FE_FETCH_R                                       ~13     $12, !2, ->28
         18    >   ASSIGN                                                   !3, ~13
   65    19        ROPE_INIT                                     3  ~16     '%3D%3D%3D%3D%3D%3D+Chunk+'
         20        ROPE_ADD                                      1  ~16     ~16, !3
         21        ROPE_END                                      2  ~15     ~16, '+%3D%3D%3D%3D%3D%3D%0A'
         22        ECHO                                                     ~15
   66    23        INIT_FCALL                                               'var_export'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
   67    26        ECHO                                                     '%0A'
   64    27      > JMP                                                      ->17
         28    >   FE_FREE                                                  $12
   68    29      > RETURN                                                   1

Function iterator_compose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 53
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 53
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 43
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 43
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 52
Branch analysis from position: 12
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/h3t39
function name:  iterator_compose
number of ops:  56
compiled vars:  !0 = $source, !1 = $steps, !2 = $step, !3 = $gen, !4 = $g, !5 = $class, !6 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2      > FE_RESET_R                                       $7      !1, ->53
          3    > > FE_FETCH_R                                               $7, !2, ->53
    7     4    >   ASSIGN                                                   !3, !0
    9     5        TYPE_CHECK                                  128  ~9      !2
          6      > JMPZ_EX                                          ~9      ~9, ->12
          7    >   INIT_FCALL                                               'is_callable'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $10     
         10        BOOL_NOT                                         ~11     $10
         11        BOOL                                             ~9      ~11
         12    > > JMPZ                                                     ~9, ->44
   10    13    >   INIT_FCALL                                               'array_shift'
         14        SEND_REF                                                 !2
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !4, $12
   11    17        INIT_FCALL                                               'array_unshift'
         18        SEND_REF                                                 !2
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                                 
   13    21        INIT_FCALL                                               'class_exists'
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $15     
         24      > JMPZ                                                     $15, ->34
   14    25    >   NEW                                              $16     'ReflectionClass'
         26        SEND_VAR_EX                                              !6
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !5, $16
   15    29        INIT_METHOD_CALL                                         !5, 'newInstanceArgs'
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $19     
         32        ASSIGN                                                   !3, $19
         33      > JMP                                                      ->43
   16    34    >   INIT_FCALL                                               'is_callable'
         35        SEND_VAR                                                 !4
         36        DO_ICALL                                         $21     
         37      > JMPZ                                                     $21, ->43
   17    38    >   INIT_USER_CALL                                0          'call_user_func_array', !4
         39        SEND_ARRAY                                               !2
         40        CHECK_UNDEF_ARGS                                         
         41        DO_FCALL                                      0  $22     
         42        ASSIGN                                                   !3, $22
         43    > > JMP                                                      ->52
   19    44    >   INIT_FCALL                                               'is_callable'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                         $24     
         47      > JMPZ                                                     $24, ->52
   20    48    >   INIT_DYNAMIC_CALL                                        !2
         49        SEND_VAR_EX                                              !3
         50        DO_FCALL                                      0  $25     
         51        ASSIGN                                                   !3, $25
    6    52    > > JMP                                                      ->3
         53    >   FE_FREE                                                  $7
   24    54      > RETURN                                                   !3
   25    55*     > RETURN                                                   null

End of function iterator_compose

Function iterator_chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 12
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 27
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 12
Branch analysis from position: 31
Branch analysis from position: 12
Branch analysis from position: 27
filename:       /in/h3t39
function name:  iterator_chunk
number of ops:  34
compiled vars:  !0 = $it, !1 = $chunkSize, !2 = $chunk, !3 = $steps, !4 = $_
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   29     3        INIT_METHOD_CALL                                         !0, 'rewind'
          4        DO_FCALL                                      0          
   30     5        ASSIGN                                                   !2, <array>
   31     6        INIT_FCALL                                               'range'
          7        SEND_VAL                                                 1
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !3, $7
   33    11      > JMP                                                      ->30
   34    12    > > FE_RESET_R                                       $9      !3, ->27
         13    > > FE_FETCH_R                                               $9, !4, ->27
   35    14    >   INIT_METHOD_CALL                                         !0, 'valid'
         15        DO_FCALL                                      0  $10     
         16        BOOL_NOT                                         ~11     $10
         17      > JMPZ                                                     ~11, ->20
   36    18    >   FE_FREE                                                  $9
         19      > JMP                                                      ->31
   39    20    >   INIT_METHOD_CALL                                         !0, 'current'
         21        DO_FCALL                                      0  $13     
         22        ASSIGN_DIM                                               !2
         23        OP_DATA                                                  $13
   40    24        INIT_METHOD_CALL                                         !0, 'next'
         25        DO_FCALL                                      0          
   34    26      > JMP                                                      ->13
         27    >   FE_FREE                                                  $9
   43    28        YIELD                                                    !2
   44    29        ASSIGN                                                   !2, <array>
   33    30    > > JMPNZ                                                    <true>, ->12
   47    31    > > JMPZ                                                     !2, ->33
   48    32    >   YIELD                                                    !2
   50    33    > > GENERATOR_RETURN                                         

End of function iterator_chunk

Function %00%7Bclosure%7D%2Fin%2Fh3t39%3A53%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 10
filename:       /in/h3t39
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $it, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   54     2      > FE_RESET_R                                       $2      !0, ->10
          3    > > FE_FETCH_R                                               $2, !1, ->10
   55     4    >   ROPE_INIT                                     3  ~4      'Value%3A+'
          5        ROPE_ADD                                      1  ~4      ~4, !1
          6        ROPE_END                                      2  ~3      ~4, '%0A'
          7        ECHO                                                     ~3
   56     8        YIELD                                                    !1
   54     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $2
   58    11      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2Fh3t39%3A53%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.67 ms | 1411 KiB | 26 Q