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($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 = [ ["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 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/uqE82
function name:  (null)
number of ops:  27
compiled vars:  !0 = $steps, !1 = $it, !2 = $c, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   ASSIGN                                                   !0, <array>
   56     1        INIT_FCALL                                               'iterator_compose'
          2        NEW                                              $5      'ArrayIterator'
          3        INIT_FCALL                                               'range'
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 127
          6        DO_ICALL                                         $6      
          7        SEND_VAR_NO_REF_EX                                       $6
          8        DO_FCALL                                      0          
          9        SEND_VAR                                                 $5
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !1, $8
   58    13      > FE_RESET_R                                       $10     !1, ->25
         14    > > FE_FETCH_R                                       ~11     $10, !2, ->25
         15    >   ASSIGN                                                   !3, ~11
   59    16        ROPE_INIT                                     3  ~14     '%3D%3D%3D%3D%3D%3D+Chunk+'
         17        ROPE_ADD                                      1  ~14     ~14, !3
         18        ROPE_END                                      2  ~13     ~14, '+%3D%3D%3D%3D%3D%3D%0A'
         19        ECHO                                                     ~13
   60    20        INIT_FCALL                                               'var_export'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                                 
   61    23        ECHO                                                     '%0A'
   58    24      > JMP                                                      ->14
         25    >   FE_FREE                                                  $10
   62    26      > RETURN                                                   1

Function iterator_compose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 56
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 56
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 47
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 37
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 46
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 55
Branch analysis from position: 15
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/uqE82
function name:  iterator_compose
number of ops:  59
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        INIT_FCALL                                               'array_reverse'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $7      
          5      > FE_RESET_R                                       $8      $7, ->56
          6    > > FE_FETCH_R                                               $8, !2, ->56
    7     7    >   ASSIGN                                                   !3, !0
    9     8        TYPE_CHECK                                  128  ~10     !2
          9      > JMPZ_EX                                          ~10     ~10, ->15
         10    >   INIT_FCALL                                               'is_callable'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $11     
         13        BOOL_NOT                                         ~12     $11
         14        BOOL                                             ~10     ~12
         15    > > JMPZ                                                     ~10, ->47
   10    16    >   INIT_FCALL                                               'array_shift'
         17        SEND_REF                                                 !2
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !4, $13
   11    20        INIT_FCALL                                               'array_unshift'
         21        SEND_REF                                                 !2
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                                 
   13    24        INIT_FCALL                                               'class_exists'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $16     
         27      > JMPZ                                                     $16, ->37
   14    28    >   NEW                                              $17     'ReflectionClass'
         29        SEND_VAR_EX                                              !6
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !5, $17
   15    32        INIT_METHOD_CALL                                         !5, 'newInstanceArgs'
         33        SEND_VAR_EX                                              !2
         34        DO_FCALL                                      0  $20     
         35        ASSIGN                                                   !3, $20
         36      > JMP                                                      ->46
   16    37    >   INIT_FCALL                                               'is_callable'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $22     
         40      > JMPZ                                                     $22, ->46
   17    41    >   INIT_USER_CALL                                0          'call_user_func_array', !4
         42        SEND_ARRAY                                               !2
         43        CHECK_UNDEF_ARGS                                         
         44        DO_FCALL                                      0  $23     
         45        ASSIGN                                                   !3, $23
         46    > > JMP                                                      ->55
   19    47    >   INIT_FCALL                                               'is_callable'
         48        SEND_VAR                                                 !2
         49        DO_ICALL                                         $25     
         50      > JMPZ                                                     $25, ->55
   20    51    >   INIT_DYNAMIC_CALL                                        !2
         52        SEND_VAR_EX                                              !3
         53        DO_FCALL                                      0  $26     
         54        ASSIGN                                                   !3, $26
    6    55    > > JMP                                                      ->6
         56    >   FE_FREE                                                  $8
   24    57      > RETURN                                                   !3
   25    58*     > 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/uqE82
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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.89 ms | 1402 KiB | 28 Q