3v4l.org

run code in 300+ PHP versions simultaneously
<?php function powerSet(Iterator $iterator){ if(!$iterator->valid()){ return yield new EmptyIterator(); } $one = $iterator->current(); $rest = new NoRewindIterator($iterator); $rest->next(); foreach(powerSet($rest) as $set){ $set = iterator_to_array($set); yield new ArrayIterator($set); yield (function($set, $one){ yield from $set; yield $one; })($set, $one); } } function baz(){ yield 1; yield 2; yield 3; yield 4; } $sets = powerSet(baz()); foreach($sets as $i => $set){ echo $i+1 . " {"; $arr = iterator_to_array($set); echo implode(", ", $arr); echo "}\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/sbaou
function name:  (null)
number of ops:  25
compiled vars:  !0 = $sets, !1 = $set, !2 = $i, !3 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'powerset'
          1        INIT_FCALL                                               'baz'
          2        DO_FCALL                                      0  $4      
          3        SEND_VAR                                                 $4
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !0, $5
   30     6      > FE_RESET_R                                       $7      !0, ->23
          7    > > FE_FETCH_R                                       ~8      $7, !1, ->23
          8    >   ASSIGN                                                   !2, ~8
   31     9        ADD                                              ~10     !2, 1
         10        CONCAT                                           ~11     ~10, '+%7B'
         11        ECHO                                                     ~11
   32    12        INIT_FCALL                                               'iterator_to_array'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !3, $12
   33    16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%2C+'
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $14     
         20        ECHO                                                     $14
   34    21        ECHO                                                     '%7D%0A'
   30    22      > JMP                                                      ->7
         23    >   FE_FREE                                                  $7
   35    24      > RETURN                                                   1

Function powerset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 39
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 39
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 39
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 39
filename:       /in/sbaou
function name:  powerSet
number of ops:  41
compiled vars:  !0 = $iterator, !1 = $one, !2 = $rest, !3 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    4     2        INIT_METHOD_CALL                                         !0, 'valid'
          3        DO_FCALL                                      0  $4      
          4        BOOL_NOT                                         ~5      $4
          5      > JMPZ                                                     ~5, ->10
    5     6    >   NEW                                              $6      'EmptyIterator'
          7        DO_FCALL                                      0          
          8        YIELD                                            $8      $6
          9      > GENERATOR_RETURN                                         
    7    10    >   INIT_METHOD_CALL                                         !0, 'current'
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !1, $9
    8    13        NEW                                              $11     'NoRewindIterator'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $11
    9    17        INIT_METHOD_CALL                                         !2, 'next'
         18        DO_FCALL                                      0          
   10    19        INIT_FCALL_BY_NAME                                       'powerSet'
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0  $15     
         22      > FE_RESET_R                                       $16     $15, ->39
         23    > > FE_FETCH_R                                               $16, !3, ->39
   11    24    >   INIT_FCALL                                               'iterator_to_array'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $17     
         27        ASSIGN                                                   !3, $17
   12    28        NEW                                              $19     'ArrayIterator'
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0          
         31        YIELD                                                    $19
   14    32        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fsbaou%3A14%240'
   17    33        INIT_DYNAMIC_CALL                                        ~22
         34        SEND_VAR_EX                                              !3
         35        SEND_VAR_EX                                              !1
         36        DO_FCALL                                      0  $23     
         37        YIELD                                                    $23
   10    38      > JMP                                                      ->23
         39    >   FE_FREE                                                  $16
   19    40      > GENERATOR_RETURN                                         

End of function powerset

Function %00%7Bclosure%7D%2Fin%2Fsbaou%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/sbaou
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $set, !1 = $one
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   15     3        YIELD_FROM                                       ~2      !0
          4        FREE                                                     ~2
   16     5        YIELD                                                    !1
   17     6      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2Fsbaou%3A14%240

Function baz:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/sbaou
function name:  baz
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   GENERATOR_CREATE                                         
   22     1        YIELD                                                    1
   23     2        YIELD                                                    2
   24     3        YIELD                                                    3
   25     4        YIELD                                                    4
   26     5      > GENERATOR_RETURN                                         

End of function baz

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
188.24 ms | 1407 KiB | 19 Q