3v4l.org

run code in 500+ PHP versions simultaneously
<?php $iterator = new ArrayIterator(range(1, 100)); function iterable_chunk(iterable $array, int $chunkSize) { for($i=0;;$i++) { $g = (function() use ($array, $chunkSize, $i) { $c = -1; $y = 0; foreach($array as $item) { $c ++; if ($c < $i*$chunkSize) { continue; } if ($c > ($i+1)*$chunkSize-1) { break; } $y ++; yield $item; } if ($y != $chunkSize) { throw new \Exception(); } })(); yield $g; } } try { foreach(iterable_chunk($iterator, 10) as $it1) { foreach ($it1 as $it) { echo $it . " "; } echo "\n"; } } catch (\Exception $e) {}
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Found catch point at position: 24
Branch analysis from position: 24
2 jumps found. (Code = 107) Position 1 = 25, Position 2 = -2
Branch analysis from position: 25
filename:       /in/clLL9
function name:  (null)
number of ops:  26
compiled vars:  !0 = $iterator, !1 = $it1, !2 = $it, !3 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   NEW                                                  $4      'ArrayIterator'
          1        INIT_FCALL                                                   'range'
          2        SEND_VAL                                                     1
          3        SEND_VAL                                                     100
          4        DO_ICALL                                             $5      
          5        SEND_VAR_NO_REF_EX                                           $5
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !0, $4
   34     8        INIT_FCALL                                                   'iterable_chunk'
          9        SEND_VAR                                                     !0
         10        SEND_VAL                                                     10
         11        DO_FCALL                                          0  $8      
         12      > FE_RESET_R                                           $9      $8, ->22
         13    > > FE_FETCH_R                                                   $9, !1, ->22
   35    14    > > FE_RESET_R                                           $10     !1, ->19
         15    > > FE_FETCH_R                                                   $10, !2, ->19
   36    16    >   CONCAT                                               ~11     !2, '+'
         17        ECHO                                                         ~11
   35    18      > JMP                                                          ->15
         19    >   FE_FREE                                                      $10
   38    20        ECHO                                                         '%0A'
   34    21      > JMP                                                          ->13
         22    >   FE_FREE                                                      $9
         23      > JMP                                                          ->25
   40    24  E > > CATCH                                           last         'Exception'
         25    > > RETURN                                                       1

Function iterable_chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
Branch analysis from position: 5
filename:       /in/clLL9
function name:  iterable_chunk
number of ops:  16
compiled vars:  !0 = $array, !1 = $chunkSize, !2 = $i, !3 = $g
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        GENERATOR_CREATE                                             
    7     3        ASSIGN                                                       !2, 0
          4      > JMP                                                          ->14
    9     5    >   DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          6        BIND_LEXICAL                                                 ~5, !0
          7        BIND_LEXICAL                                                 ~5, !1
          8        BIND_LEXICAL                                                 ~5, !2
   26     9        INIT_DYNAMIC_CALL                                            ~5
         10        DO_FCALL                                          0  $6      
    9    11        ASSIGN                                                       !3, $6
   28    12        YIELD                                                        !3
    7    13        PRE_INC                                                      !2
         14    > > JMPNZ                                                        <true>, ->5
   31    15    > > GENERATOR_RETURN                                             


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
Branch analysis from position: 22
filename:       /in/clLL9
function name:  {closure:iterable_chunk():9}
number of ops:  29
compiled vars:  !0 = $array, !1 = $chunkSize, !2 = $i, !3 = $c, !4 = $y, !5 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   GENERATOR_CREATE                                             
          1        BIND_STATIC                                                  !0
          2        BIND_STATIC                                                  !1
          3        BIND_STATIC                                                  !2
   10     4        ASSIGN                                                       !3, -1
   11     5        ASSIGN                                                       !4, 0
   12     6      > FE_RESET_R                                           $8      !0, ->22
          7    > > FE_FETCH_R                                                   $8, !5, ->22
   13     8    >   PRE_INC                                                      !3
   14     9        MUL                                                  ~10     !2, !1
         10        IS_SMALLER                                                   !3, ~10
         11      > JMPZ                                                         ~11, ->13
   15    12    > > JMP                                                          ->7
   17    13    >   ADD                                                  ~12     !2, 1
         14        MUL                                                  ~13     !1, ~12
         15        SUB                                                  ~14     ~13, 1
         16        IS_SMALLER                                                   ~14, !3
         17      > JMPZ                                                         ~15, ->19
   18    18    > > JMP                                                          ->22
   20    19    >   PRE_INC                                                      !4
   21    20        YIELD                                                        !5
   12    21      > JMP                                                          ->7
         22    >   FE_FREE                                                      $8
   23    23        IS_NOT_EQUAL                                                 !4, !1
         24      > JMPZ                                                         ~18, ->28
   24    25    >   NEW                                                  $19     'Exception'
         26        DO_FCALL                                          0          
         27      > THROW                                             0          $19
   26    28    > > GENERATOR_RETURN                                             

End of Dynamic Function 0

End of function iterable_chunk

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.25 ms | 3492 KiB | 15 Q