3v4l.org

run code in 300+ PHP versions simultaneously
<?php function chunk(\Generator $generator, $n) { for ($i = 0; $generator->valid() && $i < $n; $generator->next(), ++$i) { yield $generator->current(); } } function foo() { for ($i = 0; $i < 11; ++$i) { yield $i; } } for ($gen = foo(); $gen->valid();) { $chunk = []; foreach (chunk($gen, 3) as $value) { $chunk[] = $value; } print json_encode($chunk) . "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
Branch analysis from position: 4
Branch analysis from position: 14
filename:       /in/3eSQm
function name:  (null)
number of ops:  24
compiled vars:  !0 = $gen, !1 = $chunk, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'foo'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
          3      > JMP                                                      ->20
   16     4    >   ASSIGN                                                   !1, <array>
   17     5        INIT_FCALL                                               'chunk'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 3
          8        DO_FCALL                                      0  $6      
          9      > FE_RESET_R                                       $7      $6, ->14
         10    > > FE_FETCH_R                                               $7, !2, ->14
   18    11    >   ASSIGN_DIM                                               !1
         12        OP_DATA                                                  !2
   17    13      > JMP                                                      ->10
         14    >   FE_FREE                                                  $7
   20    15        INIT_FCALL                                               'json_encode'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $9      
         18        CONCAT                                           ~10     $9, '%0A'
         19        ECHO                                                     ~10
   15    20    >   INIT_METHOD_CALL                                         !0, 'valid'
         21        DO_FCALL                                      0  $11     
         22      > JMPNZ                                                    $11, ->4
   21    23    > > RETURN                                                   1

Function chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
Branch analysis from position: 16
Branch analysis from position: 16
filename:       /in/3eSQm
function name:  chunk
number of ops:  18
compiled vars:  !0 = $generator, !1 = $n, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
    4     3        ASSIGN                                                   !2, 0
          4      > JMP                                                      ->11
    5     5    >   INIT_METHOD_CALL                                         !0, 'current'
          6        DO_FCALL                                      0  $4      
          7        YIELD                                                    $4
    4     8        INIT_METHOD_CALL                                         !0, 'next'
          9        DO_FCALL                                      0          
         10        PRE_INC                                                  !2
         11    >   INIT_METHOD_CALL                                         !0, 'valid'
         12        DO_FCALL                                      0  $8      
         13      > JMPZ_EX                                          ~9      $8, ->16
         14    >   IS_SMALLER                                       ~10     !2, !1
         15        BOOL                                             ~9      ~10
         16    > > JMPNZ                                                    ~9, ->5
    7    17    > > GENERATOR_RETURN                                         

End of function chunk

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 3
Branch analysis from position: 7
Branch analysis from position: 3
filename:       /in/3eSQm
function name:  foo
number of ops:  8
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   GENERATOR_CREATE                                         
   10     1        ASSIGN                                                   !0, 0
          2      > JMP                                                      ->5
   11     3    >   YIELD                                                    !0
   10     4        PRE_INC                                                  !0
          5    >   IS_SMALLER                                               !0, 11
          6      > JMPNZ                                                    ~4, ->3
   13     7    > > GENERATOR_RETURN                                         

End of function foo

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.71 ms | 1407 KiB | 17 Q