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) { $prev = null; if (is_callable($it)) { $prev = $it($prev); } else if (is_object($it)) { $prev = $it; } else { $prev = new $it($prev); } } return $prev; } function cycle($it) { $saved = []; foreach ($it as $key => $val) { $saved[] = $val; yield $val; } while ($saved) { foreach ($saved as $val) { yield $val; } } } function limit($it, $count, $offset = 0) { return new LimitIterator($it, $offset, $count); } function iterator_chunk(\Traversable $it, $chunkSize) { $it->rewind(); $chunk = []; $steps = range(0, $chunkSize); while (true) { foreach ($steps as $_) { if (!$it->valid()) { break 2; } $chunk[] = $it->current(); $it->next(); } yield $chunk; $chunk = []; } if ($chunk) { yield $chunk; } } $it = iterator_chunk( new ArrayIterator(range(0, 125)) , 32); $colors = new ArrayIterator(['red', 'green', 'blue']); foreach (limit(cycle($colors), 10) as $color) { echo "$color\n"; } foreach ($it 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 = 24, Position 2 = 29
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 42
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 42
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 29
filename:       /in/leTP7
function name:  (null)
number of ops:  44
compiled vars:  !0 = $it, !1 = $colors, !2 = $color, !3 = $c, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_FCALL                                               'iterator_chunk'
   67     1        NEW                                              $5      'ArrayIterator'
          2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 125
          5        DO_ICALL                                         $6      
          6        SEND_VAR_NO_REF_EX                                       $6
          7        DO_FCALL                                      0          
          8        SEND_VAR                                                 $5
   68     9        SEND_VAL                                                 32
         10        DO_FCALL                                      0  $8      
   66    11        ASSIGN                                                   !0, $8
   70    12        NEW                                              $10     'ArrayIterator'
         13        SEND_VAL_EX                                              <array>
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $10
   72    16        INIT_FCALL                                               'limit'
         17        INIT_FCALL                                               'cycle'
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $13     
         20        SEND_VAR                                                 $13
         21        SEND_VAL                                                 10
         22        DO_FCALL                                      0  $14     
         23      > FE_RESET_R                                       $15     $14, ->29
         24    > > FE_FETCH_R                                               $15, !2, ->29
   73    25    >   NOP                                                      
         26        FAST_CONCAT                                      ~16     !2, '%0A'
         27        ECHO                                                     ~16
   72    28      > JMP                                                      ->24
         29    >   FE_FREE                                                  $15
   76    30      > FE_RESET_R                                       $17     !0, ->42
         31    > > FE_FETCH_R                                       ~18     $17, !3, ->42
         32    >   ASSIGN                                                   !4, ~18
   77    33        ROPE_INIT                                     3  ~21     '%3D%3D%3D%3D%3D%3D+Chunk+'
         34        ROPE_ADD                                      1  ~21     ~21, !4
         35        ROPE_END                                      2  ~20     ~21, '+%3D%3D%3D%3D%3D%3D%0A'
         36        ECHO                                                     ~20
   78    37        INIT_FCALL                                               'var_export'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                                 
   79    40        ECHO                                                     '%0A'
   76    41      > JMP                                                      ->31
         42    >   FE_FREE                                                  $17
   80    43      > RETURN                                                   1

Function iterator_compose:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/leTP7
function name:  iterator_compose
number of ops:  29
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, ->26
          5    > > FE_FETCH_R                                               $4, !0, ->26
    7     6    >   ASSIGN                                                   !1, null
    8     7        INIT_FCALL                                               'is_callable'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10      > JMPZ                                                     $6, ->16
    9    11    >   INIT_DYNAMIC_CALL                                        !0
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !1, $7
         15      > JMP                                                      ->25
   10    16    >   TYPE_CHECK                                  256          !0
         17      > JMPZ                                                     ~9, ->20
   11    18    >   ASSIGN                                                   !1, !0
         19      > JMP                                                      ->25
   13    20    >   FETCH_CLASS                                   0  $11     !0
         21        NEW                                              $12     $11
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !1, $12
    6    25    > > JMP                                                      ->5
         26    >   FE_FREE                                                  $4
   17    27      > RETURN                                                   !1
   18    28*     > RETURN                                                   null

End of function iterator_compose

Function cycle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
Branch analysis from position: 12
Branch analysis from position: 16
Branch analysis from position: 10
filename:       /in/leTP7
function name:  cycle
number of ops:  19
compiled vars:  !0 = $it, !1 = $saved, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   22     2        ASSIGN                                                   !1, <array>
   24     3      > FE_RESET_R                                       $5      !0, ->10
          4    > > FE_FETCH_R                                       ~6      $5, !2, ->10
          5    >   ASSIGN                                                   !3, ~6
   25     6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  !2
   26     8        YIELD                                                    !2
   24     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   29    11      > JMP                                                      ->17
   30    12    > > FE_RESET_R                                       $10     !1, ->16
         13    > > FE_FETCH_R                                               $10, !2, ->16
   31    14    >   YIELD                                                    !2
   30    15      > JMP                                                      ->13
         16    >   FE_FREE                                                  $10
   29    17    > > JMPNZ                                                    !1, ->12
   34    18    > > GENERATOR_RETURN                                         

End of function cycle

Function limit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/leTP7
function name:  limit
number of ops:  10
compiled vars:  !0 = $it, !1 = $count, !2 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
   38     3        NEW                                              $3      'LimitIterator'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !2
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8      > RETURN                                                   $3
   39     9*     > RETURN                                                   null

End of function limit

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

End of function iterator_chunk

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.4 ms | 1415 KiB | 24 Q