3v4l.org

run code in 500+ PHP versions simultaneously
<?php class BadIterator implements Iterator { private $data = [1, 2, 3, 4, 5]; private $pos = 0; public function current() { return $this; } public function key() { return $this->pos; } public function next() { $this->pos++; } public function rewind() { $this->pos = 0; } public function valid() { return $this->pos < count($this->data); } public function __toString() { return (string) $this->data[$this->pos]; } } echo "Direct iteration:\n"; foreach (new BadIterator as $val) { echo "$val\n"; } echo "Caching iteration:\n"; foreach (new CachingIterator(new BadIterator) as $val) { echo "$val\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 10
filename:       /in/dUgEg
function name:  (null)
number of ops:  25
compiled vars:  !0 = $val
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'baditerator'
   39     1        ECHO                                                         'Direct+iteration%3A%0A'
   40     2        NEW                                                  $1      'BadIterator'
          3        DO_FCALL                                          0          
          4      > FE_RESET_R                                           $3      $1, ->10
          5    > > FE_FETCH_R                                                   $3, !0, ->10
   41     6    >   NOP                                                          
          7        FAST_CONCAT                                          ~4      !0, '%0A'
          8        ECHO                                                         ~4
   40     9      > JMP                                                          ->5
         10    >   FE_FREE                                                      $3
   44    11        ECHO                                                         'Caching+iteration%3A%0A'
   45    12        NEW                                                  $5      'CachingIterator'
         13        NEW                                                  $6      'BadIterator'
         14        DO_FCALL                                          0          
         15        SEND_VAR_NO_REF_EX                                           $6
         16        DO_FCALL                                          0          
         17      > FE_RESET_R                                           $9      $5, ->23
         18    > > FE_FETCH_R                                                   $9, !0, ->23
   46    19    >   NOP                                                          
         20        FAST_CONCAT                                          ~10     !0, '%0A'
         21        ECHO                                                         ~10
   45    22      > JMP                                                          ->18
         23    >   FE_FREE                                                      $9
   47    24      > RETURN                                                       1

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

End of function current

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

End of function key

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

End of function next

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dUgEg
function name:  rewind
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   ASSIGN_OBJ                                                   'pos'
          1        OP_DATA                                                      0
   26     2      > 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/dUgEg
function name:  valid
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   FETCH_OBJ_R                                          ~0      'pos'
          1        FETCH_OBJ_R                                          ~1      'data'
          2        COUNT                                                ~2      ~1
          3        IS_SMALLER                                           ~3      ~0, ~2
          4      > RETURN                                                       ~3
   31     5*     > RETURN                                                       null

End of function valid

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dUgEg
function name:  __toString
number of ops:  8
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                          ~1      'pos'
          1        FETCH_OBJ_R                                          ~0      'data'
          2        FETCH_DIM_R                                          ~2      ~0, ~1
          3        CAST                                              6  ~3      ~2
          4        VERIFY_RETURN_TYPE                                           ~3
          5      > RETURN                                                       ~3
   36     6*       VERIFY_RETURN_TYPE                                           
          7*     > RETURN                                                       null

End of function __tostring

End of class BadIterator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
229 ms | 3345 KiB | 13 Q