3v4l.org

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

Function nums:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/ICjar
function name:  nums
number of ops:  9
compiled vars:  !0 = $ary, !1 = $x, !2 = $cmd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   GENERATOR_CREATE                                         
    3     1        ASSIGN                                                   !0, <array>
    5     2      > FE_RESET_R                                       $4      !0, ->7
          3    > > FE_FETCH_R                                               $4, !1, ->7
    6     4    >   YIELD                                            $5      !1
          5        ASSIGN                                                   !2, $5
    5     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $4
   12     8      > GENERATOR_RETURN                                         

End of function nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.33 ms | 1399 KiB | 14 Q