3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stack(... $items) { foreach ($items as $item) { if ($next = yield $item) { yield from stack(... $next); } else { yield $next; } } } $items = [1,2,3]; $stack = stack(...$items); foreach ($stack as $item) { if ($item == 1) { $stack->send(['negate', -$item]); // push something onto the stack } if ($item == 2) { continue; // remove something from the stack } if ($item == 3) { $stack->send(['exponential', $item ** 2]); // push something onto the stack } if (isset($item)) { var_dump($item); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 32
Branch analysis from position: 27
Branch analysis from position: 16
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/oUIJE
function name:  (null)
number of ops:  35
compiled vars:  !0 = $items, !1 = $stack, !2 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   18     1        INIT_FCALL                                               'stack'
          2        SEND_UNPACK                                              !0
          3        CHECK_UNDEF_ARGS                                         
          4        DO_FCALL                                      1  $4      
          5        ASSIGN                                                   !1, $4
   20     6      > FE_RESET_R                                       $6      !1, ->33
          7    > > FE_FETCH_R                                               $6, !2, ->33
   21     8    >   IS_EQUAL                                                 !2, 1
          9      > JMPZ                                                     ~7, ->16
   22    10    >   INIT_METHOD_CALL                                         !1, 'send'
         11        INIT_ARRAY                                       ~8      'negate'
         12        MUL                                              ~9      !2, -1
         13        ADD_ARRAY_ELEMENT                                ~8      ~9
         14        SEND_VAL_EX                                              ~8
         15        DO_FCALL                                      0          
   24    16    >   IS_EQUAL                                                 !2, 2
         17      > JMPZ                                                     ~11, ->19
   25    18    > > JMP                                                      ->7
   27    19    >   IS_EQUAL                                                 !2, 3
         20      > JMPZ                                                     ~12, ->27
   28    21    >   INIT_METHOD_CALL                                         !1, 'send'
         22        INIT_ARRAY                                       ~13     'exponential'
         23        POW                                              ~14     !2, 2
         24        ADD_ARRAY_ELEMENT                                ~13     ~14
         25        SEND_VAL_EX                                              ~13
         26        DO_FCALL                                      0          
   30    27    >   ISSET_ISEMPTY_CV                                         !2
         28      > JMPZ                                                     ~16, ->32
   31    29    >   INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                                 
   20    32    > > JMP                                                      ->7
         33    >   FE_FREE                                                  $6
   33    34      > RETURN                                                   1

Function stack:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 16
filename:       /in/oUIJE
function name:  stack
number of ops:  18
compiled vars:  !0 = $items, !1 = $item, !2 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_VARIADIC                                    !0      
          1        GENERATOR_CREATE                                         
    5     2      > FE_RESET_R                                       $3      !0, ->16
          3    > > FE_FETCH_R                                               $3, !1, ->16
    7     4    >   YIELD                                            $4      !1
          5        ASSIGN                                           ~5      !2, $4
          6      > JMPZ                                                     ~5, ->14
    8     7    >   INIT_FCALL_BY_NAME                                       'stack'
          8        SEND_UNPACK                                              !2
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      1  $6      
         11        YIELD_FROM                                       ~7      $6
         12        FREE                                                     ~7
         13      > JMP                                                      ->15
   10    14    >   YIELD                                                    !2
    5    15    > > JMP                                                      ->3
         16    >   FE_FREE                                                  $3
   13    17      > GENERATOR_RETURN                                         

End of function stack

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.24 ms | 1403 KiB | 16 Q