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 != null && $cmd != 'stop') echo $cmd,"\n"; if ($cmd == 'stop') { echo 'Stopped and closed generator',"\n"; return; } } } $gen = nums(); foreach ($gen as $value) { echo "$value\n"; if ($value == 26) $gen->send('reinforcements'); 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 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/hStnc
function name:  (null)
number of ops:  21
compiled vars:  !0 = $gen, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'nums'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   16     3      > FE_RESET_R                                       $4      !0, ->19
          4    > > FE_FETCH_R                                               $4, !1, ->19
   17     5    >   NOP                                                      
          6        FAST_CONCAT                                      ~5      !1, '%0A'
          7        ECHO                                                     ~5
   18     8        IS_EQUAL                                                 !1, 26
          9      > JMPZ                                                     ~6, ->13
         10    >   INIT_METHOD_CALL                                         !0, 'send'
         11        SEND_VAL_EX                                              'reinforcements'
         12        DO_FCALL                                      0          
   19    13    >   IS_EQUAL                                                 !1, 28
         14      > JMPZ                                                     ~8, ->18
   20    15    >   INIT_METHOD_CALL                                         !0, 'send'
         16        SEND_VAL_EX                                              'stop'
         17        DO_FCALL                                      0          
   16    18    > > JMP                                                      ->4
         19    >   FE_FREE                                                  $4
   22    20      > RETURN                                                   1

Function nums:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 13
filename:       /in/hStnc
function name:  nums
number of ops:  15
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, ->13
          3    > > FE_FETCH_R                                               $4, !1, ->13
    6     4    >   YIELD                                            $5      !1
          5        ASSIGN                                                   !2, $5
    8     6        IS_EQUAL                                                 !2, 'stop'
          7      > JMPZ                                                     ~7, ->12
    9     8    >   ECHO                                                     'Stopped+and+closed+generator'
          9        ECHO                                                     '%0A'
   10    10        FE_FREE                                                  $4
         11      > GENERATOR_RETURN                                         
    5    12    > > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   13    14      > GENERATOR_RETURN                                         

End of function nums

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.02 ms | 1403 KiB | 14 Q