3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! function iterator_compose() { foreach (array_reverse(func_get_args()) as $it) { if (is_callable($it)) { $prev = $it; } } } function iterator_chunk(\Traversable $it, $chunkSize) { $it = new \IteratorIterator($it); $chunk = []; $steps = range(0, $chunkSize); while (true) { foreach ($steps as $_) { $chunk[] = $it->current(); $it->next(); if (!$it->valid()) { break 1; } } yield $chunk; $chunk = []; } if ($chunk) { yield $chunk; } } $it = new ArrayIterator(range(0, 125)); foreach (iterator_chunk($it, 32) as $i => $c) { echo "====== Chunk $i ======\n"; var_export($c); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/RnA4U
function name:  (null)
number of ops:  26
compiled vars:  !0 = $it, !1 = $c, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   NEW                                              $3      'ArrayIterator'
          1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 0
          3        SEND_VAL                                                 125
          4        DO_ICALL                                         $4      
          5        SEND_VAR_NO_REF_EX                                       $4
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $3
   41     8        INIT_FCALL                                               'iterator_chunk'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 32
         11        DO_FCALL                                      0  $7      
         12      > FE_RESET_R                                       $8      $7, ->24
         13    > > FE_FETCH_R                                       ~9      $8, !1, ->24
         14    >   ASSIGN                                                   !2, ~9
   42    15        ROPE_INIT                                     3  ~12     '%3D%3D%3D%3D%3D%3D+Chunk+'
         16        ROPE_ADD                                      1  ~12     ~12, !2
         17        ROPE_END                                      2  ~11     ~12, '+%3D%3D%3D%3D%3D%3D%0A'
         18        ECHO                                                     ~11
   43    19        INIT_FCALL                                               'var_export'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                                 
   44    22        ECHO                                                     '%0A'
   41    23      > JMP                                                      ->13
         24    >   FE_FREE                                                  $8
   45    25      > RETURN                                                   1

Function iterator_compose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/RnA4U
function name:  iterator_compose
number of ops:  14
compiled vars:  !0 = $it, !1 = $prev
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_FCALL                                               'array_reverse'
          1        FUNC_GET_ARGS                                    ~2      
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4      > FE_RESET_R                                       $4      $3, ->12
          5    > > FE_FETCH_R                                               $4, !0, ->12
    7     6    >   INIT_FCALL                                               'is_callable'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9      > JMPZ                                                     $5, ->11
    8    10    >   ASSIGN                                                   !1, !0
    6    11    > > JMP                                                      ->5
         12    >   FE_FREE                                                  $4
   11    13      > RETURN                                                   null

End of function iterator_compose

Function iterator_chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
Branch analysis from position: 14
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/RnA4U
function name:  iterator_chunk
number of ops:  35
compiled vars:  !0 = $it, !1 = $chunkSize, !2 = $chunk, !3 = $steps, !4 = $_
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   15     3        NEW                                              $5      'IteratorIterator'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $5
   16     7        ASSIGN                                                   !2, <array>
   17     8        INIT_FCALL                                               'range'
          9        SEND_VAL                                                 0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   19    13      > JMP                                                      ->31
   20    14    > > FE_RESET_R                                       $11     !3, ->28
         15    > > FE_FETCH_R                                               $11, !4, ->28
   22    16    >   INIT_METHOD_CALL                                         !0, 'current'
         17        DO_FCALL                                      0  $13     
         18        ASSIGN_DIM                                               !2
         19        OP_DATA                                                  $13
   23    20        INIT_METHOD_CALL                                         !0, 'next'
         21        DO_FCALL                                      0          
   25    22        INIT_METHOD_CALL                                         !0, 'valid'
         23        DO_FCALL                                      0  $15     
         24        BOOL_NOT                                         ~16     $15
         25      > JMPZ                                                     ~16, ->27
   26    26    > > JMP                                                      ->28
   20    27    > > JMP                                                      ->15
         28    >   FE_FREE                                                  $11
   30    29        YIELD                                                    !2
   31    30        ASSIGN                                                   !2, <array>
   19    31    > > JMPNZ                                                    <true>, ->14
   34    32    > > JMPZ                                                     !2, ->34
   35    33    >   YIELD                                                    !2
   37    34    > > GENERATOR_RETURN                                         

End of function iterator_chunk

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.62 ms | 1406 KiB | 22 Q