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 the generator during iteration ',$times,"\n"; return; } } } $gen = nums(); $times = 1; foreach ($gen as $value) { echo "$value at iteration $times","\n"; 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 = 17
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/VkVK6
function name:  (null)
number of ops:  19
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, ->17
          5    > > FE_FETCH_R                                               $6, !2, ->17
   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        IS_EQUAL                                                 !2, 28
         12      > JMPZ                                                     ~10, ->16
   19    13    >   INIT_METHOD_CALL                                         !0, 'send'
         14        SEND_VAL_EX                                              'stop'
         15        DO_FCALL                                      0          
   16    16    > > JMP                                                      ->5
         17    >   FE_FREE                                                  $6
   21    18      > RETURN                                                   1

Function nums:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 6
Branch analysis from position: 18
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 6
Branch analysis from position: 18
Branch analysis from position: 6
filename:       /in/VkVK6
function name:  nums
number of ops:  19
compiled vars:  !0 = $ary, !1 = $x, !2 = $max, !3 = $cmd, !4 = $times
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                                            ~7      !0
          4        ASSIGN                                                   !2, ~7
          5      > JMP                                                      ->16
    6     6    >   FETCH_DIM_R                                      ~9      !0, !1
          7        YIELD                                            $10     ~9
          8        ASSIGN                                                   !3, $10
    7     9        IS_EQUAL                                                 !3, 'stop'
         10      > JMPZ                                                     ~12, ->15
    8    11    >   ECHO                                                     'Stopped+the+generator+during+iteration+'
         12        ECHO                                                     !4
         13        ECHO                                                     '%0A'
    9    14      > GENERATOR_RETURN                                         
    5    15    >   ASSIGN_OP                                     1          !1, 2
         16    >   IS_SMALLER                                               !1, !2
         17      > JMPNZ                                                    ~14, ->6
   12    18    > > GENERATOR_RETURN                                         

End of function nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.71 ms | 1403 KiB | 14 Q