3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nums() { $ary = [24,25,26,27,28,29,30,31,32]; $times=1; for($x = 0, $max = count($ary); $x < $max; $x += 2) { echo "iterated for ",$times++," time(s)","\n"; $cmd = (yield $ary[$x]); // yield expr if ($cmd == 'stop') { echo 'Stopped and closed generator',"\n"; return; } } } $gen = nums(); $times = 1; foreach ($gen as $value) { echo "$value at iteration $times","\n"; $times++; if ($value == 28) { // don't let it get to 32 $gen->send('stop'); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/sJB2f
function name:  (null)
number of ops:  20
compiled vars:  !0 = $gen, !1 = $times, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'nums'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   17     3        ASSIGN                                                   !1, 1
   18     4      > FE_RESET_R                                       $6      !0, ->18
          5    > > FE_FETCH_R                                               $6, !2, ->18
   19     6    >   ROPE_INIT                                     3  ~8      !2
          7        ROPE_ADD                                      1  ~8      ~8, '+at+iteration+'
          8        ROPE_END                                      2  ~7      ~8, !1
          9        ECHO                                                     ~7
         10        ECHO                                                     '%0A'
   20    11        PRE_INC                                                  !1
   21    12        IS_EQUAL                                                 !2, 28
         13      > JMPZ                                                     ~11, ->17
   22    14    >   INIT_METHOD_CALL                                         !0, 'send'
         15        SEND_VAL_EX                                              'stop'
         16        DO_FCALL                                      0          
   18    17    > > JMP                                                      ->5
         18    >   FE_FREE                                                  $6
   24    19      > RETURN                                                   1

Function nums:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 7
Branch analysis from position: 23
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 7
Branch analysis from position: 23
Branch analysis from position: 7
filename:       /in/sJB2f
function name:  nums
number of ops:  24
compiled vars:  !0 = $ary, !1 = $times, !2 = $x, !3 = $max, !4 = $cmd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   GENERATOR_CREATE                                         
    3     1        ASSIGN                                                   !0, <array>
    5     2        ASSIGN                                                   !1, 1
    6     3        ASSIGN                                                   !2, 0
          4        COUNT                                            ~8      !0
          5        ASSIGN                                                   !3, ~8
          6      > JMP                                                      ->21
    7     7    >   ECHO                                                     'iterated+for+'
          8        POST_INC                                         ~10     !1
          9        ECHO                                                     ~10
         10        ECHO                                                     '+time%28s%29'
         11        ECHO                                                     '%0A'
    8    12        FETCH_DIM_R                                      ~11     !0, !2
         13        YIELD                                            $12     ~11
         14        ASSIGN                                                   !4, $12
    9    15        IS_EQUAL                                                 !4, 'stop'
         16      > JMPZ                                                     ~14, ->20
   10    17    >   ECHO                                                     'Stopped+and+closed+generator'
         18        ECHO                                                     '%0A'
   11    19      > GENERATOR_RETURN                                         
    6    20    >   ASSIGN_OP                                     1          !2, 2
         21    >   IS_SMALLER                                               !2, !3
         22      > JMPNZ                                                    ~16, ->7
   14    23    > > GENERATOR_RETURN                                         

End of function nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.21 ms | 1407 KiB | 14 Q