3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myIterator implements Iterator { private $position = 0; private $array = [ "a", "b", "c" ]; public function __construct() { print(__METHOD__.PHP_EOL); $this->position = 0; } public function current () { print(__METHOD__.PHP_EOL); return $this->array[$this->position]; } public function next () { print(__METHOD__.PHP_EOL); ++$this->position; } public function key () { print(__METHOD__.PHP_EOL); return $this->position; } public function valid () { print(__METHOD__.PHP_EOL); return isset($this->array[$this->position]); } public function rewind () { print(__METHOD__.PHP_EOL); $this->position = 0; } } $obj = new myIterator(); //e1 while($obj->valid()) { $k = $obj->key(); $v = $obj->current(); print_r([$k,$v]); $obj->next(); } //e2 foreach($obj as $k=>$v) { print_r([$k,$v]); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
filename:       /in/goGiB
function name:  (null)
number of ops:  32
compiled vars:  !0 = $obj, !1 = $k, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'myiterator'
   40     1        NEW                                              $3      'myIterator'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   42     4      > JMP                                                      ->18
   44     5    >   INIT_METHOD_CALL                                         !0, 'key'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   45     8        INIT_METHOD_CALL                                         !0, 'current'
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !2, $8
   46    11        INIT_FCALL                                               'print_r'
         12        INIT_ARRAY                                       ~10     !1
         13        ADD_ARRAY_ELEMENT                                ~10     !2
         14        SEND_VAL                                                 ~10
         15        DO_ICALL                                                 
   47    16        INIT_METHOD_CALL                                         !0, 'next'
         17        DO_FCALL                                      0          
   42    18    >   INIT_METHOD_CALL                                         !0, 'valid'
         19        DO_FCALL                                      0  $13     
         20      > JMPNZ                                                    $13, ->5
   50    21    > > FE_RESET_R                                       $14     !0, ->30
         22    > > FE_FETCH_R                                       ~15     $14, !2, ->30
         23    >   ASSIGN                                                   !1, ~15
   52    24        INIT_FCALL                                               'print_r'
         25        INIT_ARRAY                                       ~17     !1
         26        ADD_ARRAY_ELEMENT                                ~17     !2
         27        SEND_VAL                                                 ~17
         28        DO_ICALL                                                 
   50    29      > JMP                                                      ->22
         30    >   FE_FREE                                                  $14
   53    31      > RETURN                                                   1

Class myIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/goGiB
function name:  __construct
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ECHO                                                     'myIterator%3A%3A__construct%0A'
   13     1        ASSIGN_OBJ                                               'position'
          2        OP_DATA                                                  0
   14     3      > RETURN                                                   null

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/goGiB
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ECHO                                                     'myIterator%3A%3Acurrent%0A'
   17     1        FETCH_OBJ_R                                      ~1      'position'
          2        FETCH_OBJ_R                                      ~0      'array'
          3        FETCH_DIM_R                                      ~2      ~0, ~1
          4      > RETURN                                                   ~2
   18     5*     > 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/goGiB
function name:  next
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ECHO                                                     'myIterator%3A%3Anext%0A'
   22     1        PRE_INC_OBJ                                              'position'
   23     2      > RETURN                                                   null

End of function next

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

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/goGiB
function name:  valid
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'myIterator%3A%3Avalid%0A'
   32     1        FETCH_OBJ_R                                      ~1      'position'
          2        FETCH_OBJ_IS                                     ~0      'array'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~0, ~1
          4      > RETURN                                                   ~2
   33     5*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/goGiB
function name:  rewind
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ECHO                                                     'myIterator%3A%3Arewind%0A'
   37     1        ASSIGN_OBJ                                               'position'
          2        OP_DATA                                                  0
   38     3      > RETURN                                                   null

End of function rewind

End of class myIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.07 ms | 1404 KiB | 15 Q