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; var_dump($step); 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/30qJd
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
-------------------------------------------------------------------------------------
   54     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F30qJd%3A54%240'
   59     1        INIT_ARRAY                                       ~5      ~4
   54     2        ADD_ARRAY_ELEMENT                                ~5      <array>
   53     3        ASSIGN                                                   !0, ~5
   63     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
   65    16      > FE_RESET_R                                       $12     !1, ->28
         17    > > FE_FETCH_R                                       ~13     $12, !2, ->28
         18    >   ASSIGN                                                   !3, ~13
   66    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
   67    23        INIT_FCALL                                               'var_export'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
   68    26        ECHO                                                     '%0A'
   65    27      > JMP                                                      ->17
         28    >   FE_FREE                                                  $12
   69    29      > RETURN                                                   1

Function iterator_compose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 56
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 56
Branch analysis from position: 4
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 = 3
Branch analysis from position: 3
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 = 3
Branch analysis from position: 3
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/30qJd
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      > FE_RESET_R                                       $7      !1, ->56
          3    > > FE_FETCH_R                                               $7, !2, ->56
    7     4    >   ASSIGN                                                   !3, !0
    8     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                                 
   10     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
   11    16    >   INIT_FCALL                                               'array_shift'
         17        SEND_REF                                                 !2
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !4, $13
   12    20        INIT_FCALL                                               'array_unshift'
         21        SEND_REF                                                 !2
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                                 
   14    24        INIT_FCALL                                               'class_exists'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $16     
         27      > JMPZ                                                     $16, ->37
   15    28    >   NEW                                              $17     'ReflectionClass'
         29        SEND_VAR_EX                                              !6
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !5, $17
   16    32        INIT_METHOD_CALL                                         !5, 'newInstanceArgs'
         33        SEND_VAR_EX                                              !2
         34        DO_FCALL                                      0  $20     
         35        ASSIGN                                                   !3, $20
         36      > JMP                                                      ->46
   17    37    >   INIT_FCALL                                               'is_callable'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $22     
         40      > JMPZ                                                     $22, ->46
   18    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
   20    47    >   INIT_FCALL                                               'is_callable'
         48        SEND_VAR                                                 !2
         49        DO_ICALL                                         $25     
         50      > JMPZ                                                     $25, ->55
   21    51    >   INIT_DYNAMIC_CALL                                        !2
         52        SEND_VAR_EX                                              !3
         53        DO_FCALL                                      0  $26     
         54        ASSIGN                                                   !3, $26
    6    55    > > JMP                                                      ->3
         56    >   FE_FREE                                                  $7
   25    57      > RETURN                                                   !3
   26    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/30qJd
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
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   30     3        INIT_METHOD_CALL                                         !0, 'rewind'
          4        DO_FCALL                                      0          
   31     5        ASSIGN                                                   !2, <array>
   32     6        INIT_FCALL                                               'range'
          7        SEND_VAL                                                 1
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !3, $7
   34    11      > JMP                                                      ->30
   35    12    > > FE_RESET_R                                       $9      !3, ->27
         13    > > FE_FETCH_R                                               $9, !4, ->27
   36    14    >   INIT_METHOD_CALL                                         !0, 'valid'
         15        DO_FCALL                                      0  $10     
         16        BOOL_NOT                                         ~11     $10
         17      > JMPZ                                                     ~11, ->20
   37    18    >   FE_FREE                                                  $9
         19      > JMP                                                      ->31
   40    20    >   INIT_METHOD_CALL                                         !0, 'current'
         21        DO_FCALL                                      0  $13     
         22        ASSIGN_DIM                                               !2
         23        OP_DATA                                                  $13
   41    24        INIT_METHOD_CALL                                         !0, 'next'
         25        DO_FCALL                                      0          
   35    26      > JMP                                                      ->13
         27    >   FE_FREE                                                  $9
   44    28        YIELD                                                    !2
   45    29        ASSIGN                                                   !2, <array>
   34    30    > > JMPNZ                                                    <true>, ->12
   48    31    > > JMPZ                                                     !2, ->33
   49    32    >   YIELD                                                    !2
   51    33    > > GENERATOR_RETURN                                         

End of function iterator_chunk

Function %00%7Bclosure%7D%2Fin%2F30qJd%3A54%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/30qJd
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $it, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   55     2      > FE_RESET_R                                       $2      !0, ->10
          3    > > FE_FETCH_R                                               $2, !1, ->10
   56     4    >   ROPE_INIT                                     3  ~4      'Value%3A+'
          5        ROPE_ADD                                      1  ~4      ~4, !1
          6        ROPE_END                                      2  ~3      ~4, '%0A'
          7        ECHO                                                     ~3
   57     8        YIELD                                                    !1
   55     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $2
   59    11      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2F30qJd%3A54%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.39 ms | 1411 KiB | 28 Q