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, array $steps) { $gen = $source; foreach ($steps as $spec) { if (is_array($spec) and !is_callable($spec)) { $g = array_shift($spec); array_unshift($spec, $gen); if (class_exists($g)) { $class = new \ReflectionClass($className); $gen = $class->newInstanceArgs($spec); } else if (is_callable($g)) { $gen = call_user_func_array($g, $spec); } } else if (is_callable($spec)) { $gen = $spec($gen); } } return $gen; } function iterator_chunk(\Traversable $it, $chunkSize) { $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; } } function iterator_tee(\Traversable $source, array $drains) { foreach ($source as $key => $value) { foreach ($drains as $gen) { $gen->send($value); } yield $key => $value; } } $receiver = function () { for (;;) { echo "TEE:\n"; print_r((yield)); } }; $receiver2 = function () { for (;;) { echo "Received!\n"; (yield); } }; $steps = [ function ($it) { foreach ($it as $val) { yield $val * 2; } }, "iterator_pass", ["iterator_chunk", 32], ["iterator_tee", [$receiver(), $receiver2()]] ]; $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/N1ekc
function name:  (null)
number of ops:  34
compiled vars:  !0 = $receiver, !1 = $receiver2, !2 = $steps, !3 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FN1ekc%3A74%240'
          1        ASSIGN                                                   !0, ~4
   81     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FN1ekc%3A81%241'
          3        ASSIGN                                                   !1, ~6
   89     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FN1ekc%3A89%242'
   93     5        INIT_ARRAY                                       ~9      ~8
   94     6        ADD_ARRAY_ELEMENT                                ~9      'iterator_pass'
   89     7        ADD_ARRAY_ELEMENT                                ~9      <array>
   96     8        INIT_ARRAY                                       ~10     'iterator_tee'
          9        INIT_DYNAMIC_CALL                                        !0
         10        DO_FCALL                                      0  $11     
         11        INIT_ARRAY                                       ~12     $11
         12        INIT_DYNAMIC_CALL                                        !1
         13        DO_FCALL                                      0  $13     
         14        ADD_ARRAY_ELEMENT                                ~12     $13
         15        ADD_ARRAY_ELEMENT                                ~10     ~12
         16        ADD_ARRAY_ELEMENT                                ~9      ~10
   88    17        ASSIGN                                                   !2, ~9
   99    18        INIT_FCALL                                               'iterator_pipeline'
         19        NEW                                              $15     'ArrayIterator'
         20        INIT_FCALL                                               'range'
         21        SEND_VAL                                                 0
         22        SEND_VAL                                                 127
         23        DO_ICALL                                         $16     
         24        SEND_VAR_NO_REF_EX                                       $16
         25        DO_FCALL                                      0          
         26        SEND_VAR                                                 $15
         27        SEND_VAR                                                 !2
         28        DO_FCALL                                      0  $18     
         29        ASSIGN                                                   !3, $18
  101    30        INIT_FCALL                                               'iterator_consume'
         31        SEND_VAR                                                 !3
         32        DO_FCALL                                      0          
         33      > 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/N1ekc
function name:  iterator_pipeline
number of ops:  56
compiled vars:  !0 = $source, !1 = $steps, !2 = $gen, !3 = $spec, !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 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 10
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 25
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 10
Branch analysis from position: 29
Branch analysis from position: 10
Branch analysis from position: 25
filename:       /in/N1ekc
function name:  iterator_chunk
number of ops:  32
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        ASSIGN                                                   !2, <array>
   30     4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 1
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !3, $6
   32     9      > JMP                                                      ->28
   33    10    > > FE_RESET_R                                       $8      !3, ->25
         11    > > FE_FETCH_R                                               $8, !4, ->25
   34    12    >   INIT_METHOD_CALL                                         !0, 'valid'
         13        DO_FCALL                                      0  $9      
         14        BOOL_NOT                                         ~10     $9
         15      > JMPZ                                                     ~10, ->18
   35    16    >   FE_FREE                                                  $8
         17      > JMP                                                      ->29
   38    18    >   INIT_METHOD_CALL                                         !0, 'current'
         19        DO_FCALL                                      0  $12     
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  $12
   39    22        INIT_METHOD_CALL                                         !0, 'next'
         23        DO_FCALL                                      0          
   33    24      > JMP                                                      ->11
         25    >   FE_FREE                                                  $8
   42    26        YIELD                                                    !2
   43    27        ASSIGN                                                   !2, <array>
   32    28    > > JMPNZ                                                    <true>, ->10
   46    29    > > JMPZ                                                     !2, ->31
   47    30    >   YIELD                                                    !2
   49    31    > > 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/N1ekc
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
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     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
   54     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/N1ekc
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
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   58     2      > FE_RESET_R                                       $3      !0, ->7
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->7
          4    >   ASSIGN                                                   !2, ~4
   59     5        YIELD                                                    !1, !2
   58     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   61     8      > GENERATOR_RETURN                                         

End of function iterator_pass

Function iterator_tee:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
Branch analysis from position: 15
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 15
filename:       /in/N1ekc
function name:  iterator_tee
number of ops:  17
compiled vars:  !0 = $source, !1 = $drains, !2 = $value, !3 = $key, !4 = $gen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   65     3      > FE_RESET_R                                       $5      !0, ->15
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->15
          5    >   ASSIGN                                                   !3, ~6
   66     6      > FE_RESET_R                                       $8      !1, ->12
          7    > > FE_FETCH_R                                               $8, !4, ->12
   67     8    >   INIT_METHOD_CALL                                         !4, 'send'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
   66    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $8
   70    13        YIELD                                                    !2, !3
   65    14      > JMP                                                      ->4
         15    >   FE_FREE                                                  $5
   72    16      > GENERATOR_RETURN                                         

End of function iterator_tee

Function %00%7Bclosure%7D%2Fin%2FN1ekc%3A74%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 2
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 2
Branch analysis from position: 8
Branch analysis from position: 2
filename:       /in/N1ekc
function name:  {closure}
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   GENERATOR_CREATE                                         
   75     1      > JMP                                                      ->7
   76     2    >   ECHO                                                     'TEE%3A%0A'
   77     3        INIT_FCALL                                               'print_r'
          4        YIELD                                            $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7    > > JMPNZ                                                    <true>, ->2
   79     8    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FN1ekc%3A74%240

Function %00%7Bclosure%7D%2Fin%2FN1ekc%3A81%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 2
Branch analysis from position: 5
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 2
Branch analysis from position: 5
Branch analysis from position: 2
filename:       /in/N1ekc
function name:  {closure}
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   GENERATOR_CREATE                                         
   82     1      > JMP                                                      ->4
   83     2    >   ECHO                                                     'Received%21%0A'
   84     3        YIELD                                                    
          4    > > JMPNZ                                                    <true>, ->2
   86     5    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FN1ekc%3A81%241

Function %00%7Bclosure%7D%2Fin%2FN1ekc%3A89%242:
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/N1ekc
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $it, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   90     2      > FE_RESET_R                                       $2      !0, ->7
          3    > > FE_FETCH_R                                               $2, !1, ->7
   91     4    >   MUL                                              ~3      !1, 2
          5        YIELD                                                    ~3
   90     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $2
   93     8      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FN1ekc%3A89%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.03 ms | 1410 KiB | 27 Q