3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nums() { $ary = [24,25,26,27,28,29,30,31,32]; for($x = 0, $max = count($ary); $x < $max; $x += 2) { $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/G1AdK
function name:  (null)
number of ops:  20
compiled vars:  !0 = $gen, !1 = $times, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'nums'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   15     3        ASSIGN                                                   !1, 1
   16     4      > FE_RESET_R                                       $6      !0, ->18
          5    > > FE_FETCH_R                                               $6, !2, ->18
   17     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'
   18    11        PRE_INC                                                  !1
   19    12        IS_EQUAL                                                 !2, 28
         13      > JMPZ                                                     ~11, ->17
   20    14    >   INIT_METHOD_CALL                                         !0, 'send'
         15        SEND_VAL_EX                                              'stop'
         16        DO_FCALL                                      0          
   16    17    > > JMP                                                      ->5
         18    >   FE_FREE                                                  $6
   22    19      > RETURN                                                   1

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

End of function nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.02 ms | 1403 KiB | 14 Q