3v4l.org

run code in 500+ PHP versions simultaneously
<?php function g1() { yield 2; yield 3; return 42; } function g2() { yield 1; $g1result = yield from g1(); yield 4; return $g1result; } var_dump(iterator_to_array(g2())); $g = g2(); $a = []; foreach ($g as $yielded) { $a[] = $yielded; } var_dump($a); var_dump($g->getReturn());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/UPkKV
function name:  (null)
number of ops:  27
compiled vars:  !0 = $g, !1 = $a, !2 = $yielded
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'iterator_to_array'
          2        INIT_FCALL                                                   'g2'
          3        DO_FCALL                                          0  $3      
          4        SEND_VAR                                                     $3
          5        DO_ICALL                                             $4      
          6        SEND_VAR                                                     $4
          7        DO_ICALL                                                     
   18     8        INIT_FCALL                                                   'g2'
          9        DO_FCALL                                          0  $6      
         10        ASSIGN                                                       !0, $6
   19    11        ASSIGN                                                       !1, <array>
   20    12      > FE_RESET_R                                           $9      !0, ->17
         13    > > FE_FETCH_R                                                   $9, !2, ->17
   21    14    >   ASSIGN_DIM                                                   !1
         15        OP_DATA                                                      !2
   20    16      > JMP                                                          ->13
         17    >   FE_FREE                                                      $9
   23    18        INIT_FCALL                                                   'var_dump'
         19        SEND_VAR                                                     !1
         20        DO_ICALL                                                     
   24    21        INIT_FCALL                                                   'var_dump'
         22        INIT_METHOD_CALL                                             !0, 'getReturn'
         23        DO_FCALL                                          0  $12     
         24        SEND_VAR                                                     $12
         25        DO_ICALL                                                     
         26      > RETURN                                                       1

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

End of function g1

Function g2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/UPkKV
function name:  g2
number of ops:  9
compiled vars:  !0 = $g1result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   GENERATOR_CREATE                                             
   10     1        YIELD                                                        1
   11     2        INIT_FCALL                                                   'g1'
          3        DO_FCALL                                          0  $2      
          4        YIELD_FROM                                           ~3      $2
          5        ASSIGN                                                       !0, ~3
   12     6        YIELD                                                        4
   13     7      > GENERATOR_RETURN                                             
   14     8*     > GENERATOR_RETURN                                             

End of function g2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
117.34 ms | 519 KiB | 14 Q