3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IncrementIterator implements Iterator { protected $start; protected $end; protected $current; public function __construct($start, $end) { $this->start = $start; $this->end = $end; } public function rewind() { $this->current = $this->start; } public function valid() { return $this->current <= $this->end; } public function key() { return $this->current; } public function current() { return $this->current; } public function next() { $this->current++; } } class NestedIterator implements Iterator { protected $iterators = array(); protected $lastIndex = -1; protected $iteration = 0; public function addIterator(Iterator $it) { $this->iterators[] = $it; $this->lastIndex++; } public function rewind() { foreach ($this->iterators as $it) { $it->rewind(); } $this->iteration = 0; } public function valid() { return $this->lastIndex >= 0 && $this->iterators[0]->valid(); } public function key() { return $this->iteration; } public function current() { $return = array(); foreach ($this->iterators as $it) { $return[] = $it->current(); } return $return; } public function next() { for ($i = $this->lastIndex; $i >= 0; $i--) { $this->iterators[$i]->next(); if (!$this->iterators[$i]->valid()) { continue; } for ($j = $i + 1; $j <= $this->lastIndex; $j++) { $this->iterators[$j]->rewind(); } } } } $nestedIterator = new NestedIterator(); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); $nestedIterator->addIterator(new IncrementIterator(0, 26)); foreach ($nestedIterator as $current) { var_dump($current); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 39
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/noLO6
function name:  (null)
number of ops:  41
compiled vars:  !0 = $nestedIterator, !1 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'incrementiterator'
   33     1        DECLARE_CLASS                                            'nestediterator'
   84     2        NEW                                              $2      'NestedIterator'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   85     5        INIT_METHOD_CALL                                         !0, 'addIterator'
          6        NEW                                              $5      'IncrementIterator'
          7        SEND_VAL_EX                                              0
          8        SEND_VAL_EX                                              26
          9        DO_FCALL                                      0          
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
   86    12        INIT_METHOD_CALL                                         !0, 'addIterator'
         13        NEW                                              $8      'IncrementIterator'
         14        SEND_VAL_EX                                              0
         15        SEND_VAL_EX                                              26
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $8
         18        DO_FCALL                                      0          
   87    19        INIT_METHOD_CALL                                         !0, 'addIterator'
         20        NEW                                              $11     'IncrementIterator'
         21        SEND_VAL_EX                                              0
         22        SEND_VAL_EX                                              26
         23        DO_FCALL                                      0          
         24        SEND_VAR_NO_REF_EX                                       $11
         25        DO_FCALL                                      0          
   88    26        INIT_METHOD_CALL                                         !0, 'addIterator'
         27        NEW                                              $14     'IncrementIterator'
         28        SEND_VAL_EX                                              0
         29        SEND_VAL_EX                                              26
         30        DO_FCALL                                      0          
         31        SEND_VAR_NO_REF_EX                                       $14
         32        DO_FCALL                                      0          
   90    33      > FE_RESET_R                                       $17     !0, ->39
         34    > > FE_FETCH_R                                               $17, !1, ->39
   91    35    >   INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                                 
   90    38      > JMP                                                      ->34
         39    >   FE_FREE                                                  $17
   92    40      > RETURN                                                   1

Class IncrementIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  __construct
number of ops:  7
compiled vars:  !0 = $start, !1 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN_OBJ                                               'start'
          3        OP_DATA                                                  !0
    9     4        ASSIGN_OBJ                                               'end'
          5        OP_DATA                                                  !1
   10     6      > RETURN                                                   null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  rewind
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~1      'start'
          1        ASSIGN_OBJ                                               'current'
          2        OP_DATA                                                  ~1
   14     3      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        FETCH_OBJ_R                                      ~1      'end'
          2        IS_SMALLER_OR_EQUAL                              ~2      ~0, ~1
          3      > RETURN                                                   ~2
   18     4*     > RETURN                                                   null

End of function valid

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  key
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1      > RETURN                                                   ~0
   22     2*     > RETURN                                                   null

End of function key

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  current
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1      > RETURN                                                   ~0
   26     2*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  next
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   PRE_INC_OBJ                                              'current'
   30     1      > RETURN                                                   null

End of function next

End of class IncrementIterator.

Class NestedIterator:
Function additerator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  addIterator
number of ops:  6
compiled vars:  !0 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        FETCH_OBJ_W                                      $1      'iterators'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   40     4        PRE_INC_OBJ                                              'lastIndex'
   41     5      > RETURN                                                   null

End of function additerator

Function rewind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 6
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/noLO6
function name:  rewind
number of ops:  10
compiled vars:  !0 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                      ~1      'iterators'
          1      > FE_RESET_R                                       $2      ~1, ->6
          2    > > FE_FETCH_R                                               $2, !0, ->6
   45     3    >   INIT_METHOD_CALL                                         !0, 'rewind'
          4        DO_FCALL                                      0          
   44     5      > JMP                                                      ->2
          6    >   FE_FREE                                                  $2
   48     7        ASSIGN_OBJ                                               'iteration'
          8        OP_DATA                                                  0
   49     9      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/noLO6
function name:  valid
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'lastIndex'
          1        IS_SMALLER_OR_EQUAL                              ~1      0, ~0
          2      > JMPZ_EX                                          ~1      ~1, ->8
          3    >   FETCH_OBJ_R                                      ~2      'iterators'
          4        FETCH_DIM_R                                      ~3      ~2, 0
          5        INIT_METHOD_CALL                                         ~3, 'valid'
          6        DO_FCALL                                      0  $4      
          7        BOOL                                             ~1      $4
          8    > > RETURN                                                   ~1
   53     9*     > RETURN                                                   null

End of function valid

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/noLO6
function name:  key
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_OBJ_R                                      ~0      'iteration'
          1      > RETURN                                                   ~0
   57     2*     > RETURN                                                   null

End of function key

Function current:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/noLO6
function name:  current
number of ops:  12
compiled vars:  !0 = $return, !1 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   ASSIGN                                                   !0, <array>
   62     1        FETCH_OBJ_R                                      ~3      'iterators'
          2      > FE_RESET_R                                       $4      ~3, ->9
          3    > > FE_FETCH_R                                               $4, !1, ->9
   63     4    >   INIT_METHOD_CALL                                         !1, 'current'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $6
   62     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $4
   66    10      > RETURN                                                   !0
   67    11*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 3
Branch analysis from position: 28
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
filename:       /in/noLO6
function name:  next
number of ops:  29
compiled vars:  !0 = $i, !1 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   FETCH_OBJ_R                                      ~2      'lastIndex'
          1        ASSIGN                                                   !0, ~2
          2      > JMP                                                      ->26
   71     3    >   FETCH_OBJ_R                                      ~4      'iterators'
          4        FETCH_DIM_R                                      ~5      ~4, !0
          5        INIT_METHOD_CALL                                         ~5, 'next'
          6        DO_FCALL                                      0          
   73     7        FETCH_OBJ_R                                      ~7      'iterators'
          8        FETCH_DIM_R                                      ~8      ~7, !0
          9        INIT_METHOD_CALL                                         ~8, 'valid'
         10        DO_FCALL                                      0  $9      
         11        BOOL_NOT                                         ~10     $9
         12      > JMPZ                                                     ~10, ->14
   74    13    > > JMP                                                      ->25
   77    14    >   ADD                                              ~11     !0, 1
         15        ASSIGN                                                   !1, ~11
         16      > JMP                                                      ->22
   78    17    >   FETCH_OBJ_R                                      ~13     'iterators'
         18        FETCH_DIM_R                                      ~14     ~13, !1
         19        INIT_METHOD_CALL                                         ~14, 'rewind'
         20        DO_FCALL                                      0          
   77    21        PRE_INC                                                  !1
         22    >   FETCH_OBJ_R                                      ~17     'lastIndex'
         23        IS_SMALLER_OR_EQUAL                                      !1, ~17
         24      > JMPNZ                                                    ~18, ->17
   70    25    >   PRE_DEC                                                  !0
         26    >   IS_SMALLER_OR_EQUAL                                      0, !0
         27      > JMPNZ                                                    ~20, ->3
   81    28    > > RETURN                                                   null

End of function next

End of class NestedIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.32 ms | 1412 KiB | 15 Q