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 $iterationCount = 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->iterationCount; } 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()) { $this->iterationCount++; for ($j = $i + 1; $j <= $this->lastIndex; $j++) { $this->iterators[$j]->rewind(); } break; } } } } $nestedIterator = new NestedIterator(); $nestedIterator->addIterator(new IncrementIterator(0, 5)); $nestedIterator->addIterator(new IncrementIterator(0, 5)); $nestedIterator->addIterator(new IncrementIterator(0, 5)); $nestedIterator->addIterator(new IncrementIterator(0, 5)); foreach ($nestedIterator as $key => $current) { list($a, $b, $c, $d) = $current; echo "[$key] => $a, $b, $c, $d\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 59
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 59
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/Ei9PN
function name:  (null)
number of ops:  61
compiled vars:  !0 = $nestedIterator, !1 = $current, !2 = $key, !3 = $a, !4 = $b, !5 = $c, !6 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'incrementiterator'
   33     1        DECLARE_CLASS                                            'nestediterator'
   86     2        NEW                                              $7      'NestedIterator'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $7
   87     5        INIT_METHOD_CALL                                         !0, 'addIterator'
          6        NEW                                              $10     'IncrementIterator'
          7        SEND_VAL_EX                                              0
          8        SEND_VAL_EX                                              5
          9        DO_FCALL                                      0          
         10        SEND_VAR_NO_REF_EX                                       $10
         11        DO_FCALL                                      0          
   88    12        INIT_METHOD_CALL                                         !0, 'addIterator'
         13        NEW                                              $13     'IncrementIterator'
         14        SEND_VAL_EX                                              0
         15        SEND_VAL_EX                                              5
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $13
         18        DO_FCALL                                      0          
   89    19        INIT_METHOD_CALL                                         !0, 'addIterator'
         20        NEW                                              $16     'IncrementIterator'
         21        SEND_VAL_EX                                              0
         22        SEND_VAL_EX                                              5
         23        DO_FCALL                                      0          
         24        SEND_VAR_NO_REF_EX                                       $16
         25        DO_FCALL                                      0          
   90    26        INIT_METHOD_CALL                                         !0, 'addIterator'
         27        NEW                                              $19     'IncrementIterator'
         28        SEND_VAL_EX                                              0
         29        SEND_VAL_EX                                              5
         30        DO_FCALL                                      0          
         31        SEND_VAR_NO_REF_EX                                       $19
         32        DO_FCALL                                      0          
   92    33      > FE_RESET_R                                       $22     !0, ->59
         34    > > FE_FETCH_R                                       ~23     $22, !1, ->59
         35    >   ASSIGN                                                   !2, ~23
   93    36        QM_ASSIGN                                        ~25     !1
         37        FETCH_LIST_R                                     $26     ~25, 0
         38        ASSIGN                                                   !3, $26
         39        FETCH_LIST_R                                     $28     ~25, 1
         40        ASSIGN                                                   !4, $28
         41        FETCH_LIST_R                                     $30     ~25, 2
         42        ASSIGN                                                   !5, $30
         43        FETCH_LIST_R                                     $32     ~25, 3
         44        ASSIGN                                                   !6, $32
         45        FREE                                                     ~25
   95    46        ROPE_INIT                                    11  ~35     '%5B'
         47        ROPE_ADD                                      1  ~35     ~35, !2
         48        ROPE_ADD                                      2  ~35     ~35, '%5D+%3D%3E+'
         49        ROPE_ADD                                      3  ~35     ~35, !3
         50        ROPE_ADD                                      4  ~35     ~35, '%2C+'
         51        ROPE_ADD                                      5  ~35     ~35, !4
         52        ROPE_ADD                                      6  ~35     ~35, '%2C+'
         53        ROPE_ADD                                      7  ~35     ~35, !5
         54        ROPE_ADD                                      8  ~35     ~35, '%2C+'
         55        ROPE_ADD                                      9  ~35     ~35, !6
         56        ROPE_END                                     10  ~34     ~35, '%0A'
         57        ECHO                                                     ~34
   92    58      > JMP                                                      ->34
         59    >   FE_FREE                                                  $22
   96    60      > RETURN                                                   1

Class IncrementIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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/Ei9PN
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      'iterationCount'
          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/Ei9PN
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 = 12, Position 2 = 25
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 16
Branch analysis from position: 24
Branch analysis from position: 16
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
filename:       /in/Ei9PN
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      > JMPZ                                                     $9, ->25
   74    12    >   PRE_INC_OBJ                                              'iterationCount'
   76    13        ADD                                              ~11     !0, 1
         14        ASSIGN                                                   !1, ~11
         15      > JMP                                                      ->21
   77    16    >   FETCH_OBJ_R                                      ~13     'iterators'
         17        FETCH_DIM_R                                      ~14     ~13, !1
         18        INIT_METHOD_CALL                                         ~14, 'rewind'
         19        DO_FCALL                                      0          
   76    20        PRE_INC                                                  !1
         21    >   FETCH_OBJ_R                                      ~17     'lastIndex'
         22        IS_SMALLER_OR_EQUAL                                      !1, ~17
         23      > JMPNZ                                                    ~18, ->16
   80    24    > > JMP                                                      ->28
   70    25    >   PRE_DEC                                                  !0
         26    >   IS_SMALLER_OR_EQUAL                                      0, !0
         27      > JMPNZ                                                    ~20, ->3
   83    28    > > RETURN                                                   null

End of function next

End of class NestedIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.66 ms | 1411 KiB | 13 Q