3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen($a = 0) { yield 1; yield 2; yield 3; yield 4; yield 5; } function bar($gen) { yield from $gen; } $gen = gen(); $gens[] = bar($gen); $gens[] = bar($gen); do { foreach ($gens as $g) { echo "Current: "; var_dump($g->current()); // Notice - We are advancing the underlying gen, not either of the things // gens in the array. If we delegate properly, then our other generators // should be implicitly advancing as well. $gen->next(); } } while($gen->valid()); var_dump($gens[1]->valid());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 13
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 24
filename:       /in/JFrIb
function name:  (null)
number of ops:  35
compiled vars:  !0 = $gen, !1 = $gens, !2 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'gen'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   14     3        INIT_FCALL                                               'bar'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $6      
          6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  $6
   15     8        INIT_FCALL                                               'bar'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $8      
         11        ASSIGN_DIM                                               !1
         12        OP_DATA                                                  $8
   17    13    > > FE_RESET_R                                       $9      !1, ->24
         14    > > FE_FETCH_R                                               $9, !2, ->24
   18    15    >   ECHO                                                     'Current%3A+'
   19    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !2, 'current'
         18        DO_FCALL                                      0  $10     
         19        SEND_VAR                                                 $10
         20        DO_ICALL                                                 
   23    21        INIT_METHOD_CALL                                         !0, 'next'
         22        DO_FCALL                                      0          
   17    23      > JMP                                                      ->14
         24    >   FE_FREE                                                  $9
   25    25        INIT_METHOD_CALL                                         !0, 'valid'
         26        DO_FCALL                                      0  $13     
         27      > JMPNZ                                                    $13, ->13
   26    28    >   INIT_FCALL                                               'var_dump'
         29        FETCH_DIM_R                                      ~14     !1, 1
         30        INIT_METHOD_CALL                                         ~14, 'valid'
         31        DO_FCALL                                      0  $15     
         32        SEND_VAR                                                 $15
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Function gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/JFrIb
function name:  gen
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      0
          1        GENERATOR_CREATE                                         
    3     2        YIELD                                                    1
    4     3        YIELD                                                    2
    5     4        YIELD                                                    3
    6     5        YIELD                                                    4
    7     6        YIELD                                                    5
    8     7      > GENERATOR_RETURN                                         

End of function gen

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/JFrIb
function name:  bar
number of ops:  5
compiled vars:  !0 = $gen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   10     2        YIELD_FROM                                       ~1      !0
          3        FREE                                                     ~1
   11     4      > GENERATOR_RETURN                                         

End of function bar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.2 ms | 1403 KiB | 18 Q