3v4l.org

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

Function generate_ints:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 10
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 10
filename:       /in/jAnbf
function name:  generate_ints
number of ops:  12
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, ->10
          7    > > FE_FETCH_R                                               $3, !1, ->10
    5     8    >   YIELD                                                    !1
    4     9      > JMP                                                      ->7
         10    >   FE_FREE                                                  $3
    7    11      > GENERATOR_RETURN                                         

End of function generate_ints

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.53 ms | 1394 KiB | 18 Q