3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1($a = 0) { $i = 0; while($i < 5) { yield $a; $a = $a + 1; $i = $i + 1; } return $a * 5; } function yf() { $bs = yield from []; echo "Done with the garbage iterator. Should return nothing. Actual return value below:\n"; var_dump($bs); $som = yield from [1, 2, 3]; echo "Done with the iterator. Result was $som\n"; $res = yield from gen1(); echo "Done with the first generator. Result was $res\n"; $oth = yield from gen1($res); echo "Done with the second generator. Result was $oth\n"; return $oth; } $g = yf(); foreach($g as $val) { var_dump($val); } var_dump($g->getReturn());
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/3oSO7
function name:  (null)
number of ops:  16
compiled vars:  !0 = $g, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'yf'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   27     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
   28    10        INIT_FCALL                                               'var_dump'
         11        INIT_METHOD_CALL                                         !0, 'getReturn'
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
Branch analysis from position: 4
filename:       /in/3oSO7
function name:  gen1
number of ops:  14
compiled vars:  !0 = $a, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      0
          1        GENERATOR_CREATE                                         
    4     2        ASSIGN                                                   !1, 0
    5     3      > JMP                                                      ->9
    6     4    >   YIELD                                                    !0
    7     5        ADD                                              ~4      !0, 1
          6        ASSIGN                                                   !0, ~4
    8     7        ADD                                              ~6      !1, 1
          8        ASSIGN                                                   !1, ~6
    5     9    >   IS_SMALLER                                               !1, 5
         10      > JMPNZ                                                    ~8, ->4
   10    11    >   MUL                                              ~9      !0, 5
         12      > GENERATOR_RETURN                                         
   11    13*     > GENERATOR_RETURN                                         

End of function gen1

Function yf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/3oSO7
function name:  yf
number of ops:  32
compiled vars:  !0 = $bs, !1 = $som, !2 = $res, !3 = $oth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   GENERATOR_CREATE                                         
   14     1        YIELD_FROM                                       ~4      <array>
          2        ASSIGN                                                   !0, ~4
   15     3        ECHO                                                     'Done+with+the+garbage+iterator.+Should+return+nothing.+Actual+return+value+below%3A%0A'
   16     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   17     7        YIELD_FROM                                       ~7      <array>
          8        ASSIGN                                                   !1, ~7
   18     9        ROPE_INIT                                     3  ~10     'Done+with+the+iterator.+Result+was+'
         10        ROPE_ADD                                      1  ~10     ~10, !1
         11        ROPE_END                                      2  ~9      ~10, '%0A'
         12        ECHO                                                     ~9
   19    13        INIT_FCALL                                               'gen1'
         14        DO_FCALL                                      0  $12     
         15        YIELD_FROM                                       ~13     $12
         16        ASSIGN                                                   !2, ~13
   20    17        ROPE_INIT                                     3  ~16     'Done+with+the+first+generator.+Result+was+'
         18        ROPE_ADD                                      1  ~16     ~16, !2
         19        ROPE_END                                      2  ~15     ~16, '%0A'
         20        ECHO                                                     ~15
   21    21        INIT_FCALL                                               'gen1'
         22        SEND_VAR                                                 !2
         23        DO_FCALL                                      0  $18     
         24        YIELD_FROM                                       ~19     $18
         25        ASSIGN                                                   !3, ~19
   22    26        ROPE_INIT                                     3  ~22     'Done+with+the+second+generator.+Result+was+'
         27        ROPE_ADD                                      1  ~22     ~22, !3
         28        ROPE_END                                      2  ~21     ~22, '%0A'
         29        ECHO                                                     ~21
   23    30      > GENERATOR_RETURN                                         
   24    31*     > GENERATOR_RETURN                                         

End of function yf

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.12 ms | 1403 KiB | 18 Q