3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyIter implements Iterator { private $a; private $key = 0; public function __construct(array $a) { $this->a = array_values($a); } public function key() { return $this->key; } public function rewind() { $this->key = 0; } public function valid() { echo __METHOD__, PHP_EOL; return isset($this->a[$this->key]); } public function next() { echo __METHOD__, PHP_EOL; $this->key++; } public function current() { echo __METHOD__, PHP_EOL; return $this->a[$this->key]; } } $ilist = new MyIter(array('A', 'B', 'C', 'D')); foreach ($ilist as $var) { echo "var = $var\n"; echo "current = ", print_r(current($ilist), true), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/a7NtE
function name:  (null)
number of ops:  24
compiled vars:  !0 = $ilist, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'myiter'
   42     1        NEW                                              $2      'MyIter'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   43     5      > FE_RESET_R                                       $5      !0, ->22
          6    > > FE_FETCH_R                                               $5, !1, ->22
   44     7    >   ROPE_INIT                                     3  ~7      'var+%3D+'
          8        ROPE_ADD                                      1  ~7      ~7, !1
          9        ROPE_END                                      2  ~6      ~7, '%0A'
         10        ECHO                                                     ~6
   45    11        ECHO                                                     'current+%3D+'
         12        INIT_FCALL                                               'print_r'
         13        INIT_FCALL                                               'current'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16        SEND_VAR                                                 $9
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $10     
         19        ECHO                                                     $10
         20        ECHO                                                     '%0A'
   43    21      > JMP                                                      ->6
         22    >   FE_FREE                                                  $5
   46    23      > RETURN                                                   1

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

End of function __construct

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a7NtE
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      'key'
          1      > RETURN                                                   ~0
   16     2*     > RETURN                                                   null

End of function key

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a7NtE
function name:  rewind
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN_OBJ                                               'key'
          1        OP_DATA                                                  0
   21     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/a7NtE
function name:  valid
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ECHO                                                     'MyIter%3A%3Avalid'
          1        ECHO                                                     '%0A'
   26     2        FETCH_OBJ_R                                      ~1      'key'
          3        FETCH_OBJ_IS                                     ~0      'a'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~0, ~1
          5      > RETURN                                                   ~2
   27     6*     > RETURN                                                   null

End of function valid

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a7NtE
function name:  next
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'MyIter%3A%3Anext'
          1        ECHO                                                     '%0A'
   32     2        PRE_INC_OBJ                                              'key'
   33     3      > RETURN                                                   null

End of function next

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a7NtE
function name:  current
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ECHO                                                     'MyIter%3A%3Acurrent'
          1        ECHO                                                     '%0A'
   38     2        FETCH_OBJ_R                                      ~1      'key'
          3        FETCH_OBJ_R                                      ~0      'a'
          4        FETCH_DIM_R                                      ~2      ~0, ~1
          5      > RETURN                                                   ~2
   39     6*     > RETURN                                                   null

End of function current

End of class MyIter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.59 ms | 1400 KiB | 19 Q