3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! function iterator_pipeline(\Traversable $source, $steps) { $gen = $source; foreach ($steps as $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; } } function iterator_consume(\Traversable $it) { foreach ($it as $key => $value) {} } function iterator_pass(\Traversable $it) { foreach ($it as $key => $value) { yield $key => $value; } } $steps = [ function($it) { foreach ($it as $val) { yield $val * 2; } }, "iterator_pass", ["iterator_chunk", 32], function($it) { foreach ($it as $val) { print_r($val); yield $val; } } ]; $it = iterator_pipeline(new \ArrayIterator(range(0, 127)), $steps); iterator_consume($it);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t9M1J
function name:  (null)
number of ops:  23
compiled vars:  !0 = $steps, !1 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ft9M1J%3A65%240'
   69     1        INIT_ARRAY                                       ~3      ~2
   70     2        ADD_ARRAY_ELEMENT                                ~3      'iterator_pass'
   65     3        ADD_ARRAY_ELEMENT                                ~3      <array>
   72     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ft9M1J%3A72%241'
   77     5        ADD_ARRAY_ELEMENT                                ~3      ~4
   64     6        ASSIGN                                                   !0, ~3
   80     7        INIT_FCALL                                               'iterator_pipeline'
          8        NEW                                              $6      'ArrayIterator'
          9        INIT_FCALL                                               'range'
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 127
         12        DO_ICALL                                         $7      
         13        SEND_VAR_NO_REF_EX                                       $7
         14        DO_FCALL                                      0          
         15        SEND_VAR                                                 $6
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $9      
         18        ASSIGN                                                   !1, $9
   82    19        INIT_FCALL                                               'iterator_consume'
         20        SEND_VAR                                                 !1
         21        DO_FCALL                                      0          
         22      > RETURN                                                   1

Function iterator_pipeline:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 53
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 53
Branch analysis from position: 5
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 = 4
Branch analysis from position: 4
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 = 4
Branch analysis from position: 4
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/t9M1J
function name:  iterator_pipeline
number of ops:  56
compiled vars:  !0 = $source, !1 = $steps, !2 = $gen, !3 = $step, !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        ASSIGN                                                   !2, !0
    8     3      > FE_RESET_R                                       $8      !1, ->53
          4    > > FE_FETCH_R                                               $8, !3, ->53
    9     5    >   TYPE_CHECK                                  128  ~9      !3
          6      > JMPZ_EX                                          ~9      ~9, ->12
          7    >   INIT_FCALL                                               'is_callable'
          8        SEND_VAR                                                 !3
          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                                                 !3
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !4, $12
   11    17        INIT_FCALL                                               'array_unshift'
         18        SEND_REF                                                 !3
         19        SEND_VAR                                                 !2
         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                                              !3
         31        DO_FCALL                                      0  $19     
         32        ASSIGN                                                   !2, $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                                               !3
         40        CHECK_UNDEF_ARGS                                         
         41        DO_FCALL                                      0  $22     
         42        ASSIGN                                                   !2, $22
         43    > > JMP                                                      ->52
   19    44    >   INIT_FCALL                                               'is_callable'
         45        SEND_VAR                                                 !3
         46        DO_ICALL                                         $24     
         47      > JMPZ                                                     $24, ->52
   20    48    >   INIT_DYNAMIC_CALL                                        !3
         49        SEND_VAR_EX                                              !2
         50        DO_FCALL                                      0  $25     
         51        ASSIGN                                                   !2, $25
    8    52    > > JMP                                                      ->4
         53    >   FE_FREE                                                  $8
   24    54      > RETURN                                                   !2
   25    55*     > RETURN                                                   null

End of function iterator_pipeline

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/t9M1J
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 iterator_consume:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/t9M1J
function name:  iterator_consume
number of ops:  7
compiled vars:  !0 = $it, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   54     1      > FE_RESET_R                                       $3      !0, ->5
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->5
          3    >   ASSIGN                                                   !2, ~4
          4      > JMP                                                      ->2
          5    >   FE_FREE                                                  $3
   55     6      > RETURN                                                   null

End of function iterator_consume

Function iterator_pass:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/t9M1J
function name:  iterator_pass
number of ops:  9
compiled vars:  !0 = $it, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   59     2      > FE_RESET_R                                       $3      !0, ->7
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->7
          4    >   ASSIGN                                                   !2, ~4
   60     5        YIELD                                                    !1, !2
   59     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   62     8      > GENERATOR_RETURN                                         

End of function iterator_pass

Function %00%7Bclosure%7D%2Fin%2Ft9M1J%3A65%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/t9M1J
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $it, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   66     2      > FE_RESET_R                                       $2      !0, ->7
          3    > > FE_FETCH_R                                               $2, !1, ->7
   67     4    >   MUL                                              ~3      !1, 2
          5        YIELD                                                    ~3
   66     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $2
   69     8      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2Ft9M1J%3A65%240

Function %00%7Bclosure%7D%2Fin%2Ft9M1J%3A72%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 9
filename:       /in/t9M1J
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $it, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   73     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   74     4    >   INIT_FCALL                                               'print_r'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                                 
   75     7        YIELD                                                    !1
   73     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   77    10      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2Ft9M1J%3A72%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.54 ms | 1414 KiB | 27 Q