3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generate_ints($n){ foreach ( range(0,$n) as $number) { $number = (yield $number); yield $number; } } $gen = generate_ints(5); // iterable object can be used in foreach foreach ($gen as $g) { $c = $gen->current(); echo $c; if ($c == 4) { $gen->send(9); // injecting a value if ($gen->current() == 9) return; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/cDTEa
function name:  (null)
number of ops:  24
compiled vars:  !0 = $gen, !1 = $g, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'generate_ints'
          1        SEND_VAL                                                 5
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !0, $3
   13     4      > FE_RESET_R                                       $5      !0, ->22
          5    > > FE_FETCH_R                                               $5, !1, ->22
   14     6    >   INIT_METHOD_CALL                                         !0, 'current'
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   15     9        ECHO                                                     !2
   16    10        IS_EQUAL                                                 !2, 4
         11      > JMPZ                                                     ~8, ->21
   17    12    >   INIT_METHOD_CALL                                         !0, 'send'
         13        SEND_VAL_EX                                              9
         14        DO_FCALL                                      0          
   18    15        INIT_METHOD_CALL                                         !0, 'current'
         16        DO_FCALL                                      0  $10     
         17        IS_EQUAL                                                 $10, 9
         18      > JMPZ                                                     ~11, ->21
         19    >   FE_FREE                                                  $5
         20      > RETURN                                                   null
   13    21    > > JMP                                                      ->5
         22    >   FE_FREE                                                  $5
   20    23      > RETURN                                                   1

Function generate_ints:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
filename:       /in/cDTEa
function name:  generate_ints
number of ops:  14
compiled vars:  !0 = $n, !1 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    4     2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 0
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > FE_RESET_R                                       $3      $2, ->12
          7    > > FE_FETCH_R                                               $3, !1, ->12
    5     8    >   YIELD                                            $4      !1
          9        ASSIGN                                                   !1, $4
    6    10        YIELD                                                    !1
    4    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $3
    8    13      > GENERATOR_RETURN                                         

End of function generate_ints

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.02 ms | 1402 KiB | 16 Q