3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
Jump found. Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
Jump found. Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
Jump found. Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
Jump found. Position 1 = -2
Branch analysis from position: 11
filename:       /in/3oSO7
function name:  (null)
number of ops:  18
compiled vars:  !0 = $g, !1 = $val
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  13     1        NOP                                                      
  26     2        INIT_FCALL                                               'yf'
         3        DO_FCALL                                      0  $2      
         4        ASSIGN                                                   !0, $2
  27     5      > FE_RESET_R                                       $4      !0, ->11
         6    > > FE_FETCH_R                                               $4, !1, ->11
         7    >   INIT_FCALL                                               'var_dump'
         8        SEND_VAR                                                 !1
         9        DO_ICALL                                                 
        10      > JMP                                                      ->6
        11    >   FE_FREE                                                  $4
  28    12        INIT_FCALL                                               'var_dump'
        13        INIT_METHOD_CALL                                         !0, 'getReturn'
        14        DO_FCALL                                      0  $6      
        15        SEND_VAR                                                 $6
        16        DO_ICALL                                                 
        17      > RETURN                                                   1

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

End of function gen1

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

End of function yf

Generated using Vulcan Logic Dumper, using php 7.3.0