3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } /** function yieldFrom() { $iter = gen1(); foreach($iter as $val) { yield $val; } } /**/ /**/ function yftest() { yield from gen1(); echo "Dawg\n"; yield from gen1(); yield from [1, 2, 3]; } /**/ $g = yftest(); //$g = gen1(); // TEST - Iteration /**/ foreach($g as $val) { var_dump($val); } /**/ // TEST - Sending /** $g->next(); $g->send(10); $g->send(20); /**/
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/T2a7F
function name:  (null)
number of ops:  11
compiled vars:  !0 = $g, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'yftest'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   31     3      > FE_RESET_R                                       $4      !0, ->9
          4    > > FE_FETCH_R                                               $4, !1, ->9
          5    >   INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > JMP                                                      ->4
          9    >   FE_FREE                                                  $4
   38    10      > RETURN                                                   1

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/T2a7F
function name:  gen1
number of ops:  11
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   GENERATOR_CREATE                                         
    4     1        YIELD                                            $2      1
          2        ASSIGN                                                   !0, $2
    5     3        ECHO                                                     'Sup%21%0A'
    6     4        YIELD                                            $4      2
          5        ASSIGN                                                   !1, $4
    7     6        INIT_FCALL                                               'var_dump'
          7        ADD                                              ~6      !0, !1
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
    8    10      > GENERATOR_RETURN                                         

End of function gen1

Function yftest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/T2a7F
function name:  yftest
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   GENERATOR_CREATE                                         
   20     1        INIT_FCALL                                               'gen1'
          2        DO_FCALL                                      0  $0      
          3        YIELD_FROM                                       ~1      $0
          4        FREE                                                     ~1
   21     5        ECHO                                                     'Dawg%0A'
   22     6        INIT_FCALL                                               'gen1'
          7        DO_FCALL                                      0  $2      
          8        YIELD_FROM                                       ~3      $2
          9        FREE                                                     ~3
   23    10        YIELD_FROM                                       ~4      <array>
         11        FREE                                                     ~4
   24    12      > GENERATOR_RETURN                                         

End of function yftest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.25 ms | 1403 KiB | 18 Q