3v4l.org

run code in 300+ PHP versions simultaneously
<?php class values implements Iterator { private $_data = null; // array or object private $_keys = array(); private $_key = false; public function __construct($data = null){ $this->_data = $data; } public function current(){ return $this->_data->{"{$this->_key}"}; } public function key(){ return $this->_key; } public function next(){ $this->_key = next($this->_keys); } public function rewind(){ if (is_object($this->_data)){ $this->_keys = array_keys(get_object_vars($this->_data)); } $this->_key = reset($this->_keys); } public function valid(){ if (false === $this->_key){ return false; } return isset($this->_data->{"{$this->_key}"}); } } $values = new values(new DateTime()); for ($i = 0; $i < 100; $i++){ foreach($values as $k => $v) { var_dump($k, $v); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 9
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 9
Branch analysis from position: 21
Branch analysis from position: 9
Branch analysis from position: 17
filename:       /in/HADgN
function name:  (null)
number of ops:  22
compiled vars:  !0 = $values, !1 = $i, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'values'
   34     1        NEW                                              $4      'values'
          2        NEW                                              $5      'DateTime'
          3        DO_FCALL                                      0          
          4        SEND_VAR_NO_REF_EX                                       $5
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $4
   36     7        ASSIGN                                                   !1, 0
          8      > JMP                                                      ->19
   37     9    > > FE_RESET_R                                       $10     !0, ->17
         10    > > FE_FETCH_R                                       ~11     $10, !2, ->17
         11    >   ASSIGN                                                   !3, ~11
   38    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !3
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   37    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $10
   36    18        PRE_INC                                                  !1
         19    >   IS_SMALLER                                               !1, 100
         20      > JMPNZ                                                    ~15, ->9
   40    21    > > RETURN                                                   1

Class values:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HADgN
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                        !0      null
    9     1        ASSIGN_OBJ                                               '_data'
          2        OP_DATA                                                  !0
   10     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/HADgN
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~1      '_key'
          1        CAST                                          6  ~2      ~1
          2        FETCH_OBJ_R                                      ~0      '_data'
          3        FETCH_OBJ_R                                      ~3      ~0, ~2
          4      > RETURN                                                   ~3
   13     5*     > 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/HADgN
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 next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HADgN
function name:  next
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $1      '_keys'
          2        SEND_REF                                                 $1
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               '_key'
          5        OP_DATA                                                  $2
   19     6      > RETURN                                                   null

End of function next

Function rewind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/HADgN
function name:  rewind
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                      ~0      '_data'
          1        TYPE_CHECK                                  256          ~0
          2      > JMPZ                                                     ~1, ->12
   22     3    >   INIT_FCALL                                               'array_keys'
          4        INIT_FCALL                                               'get_object_vars'
          5        FETCH_OBJ_R                                      ~3      '_data'
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                         $5      
         10        ASSIGN_OBJ                                               '_keys'
         11        OP_DATA                                                  $5
   24    12    >   INIT_FCALL                                               'reset'
         13        FETCH_OBJ_W                                      $7      '_keys'
         14        SEND_REF                                                 $7
         15        DO_ICALL                                         $8      
         16        ASSIGN_OBJ                                               '_key'
         17        OP_DATA                                                  $8
   25    18      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HADgN
function name:  valid
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      '_key'
          1        TYPE_CHECK                                    4          ~0
          2      > JMPZ                                                     ~1, ->4
   28     3    > > RETURN                                                   <false>
   30     4    >   FETCH_OBJ_R                                      ~3      '_key'
          5        CAST                                          6  ~4      ~3
          6        FETCH_OBJ_IS                                     ~2      '_data'
          7        ISSET_ISEMPTY_PROP_OBJ                           ~5      ~2, ~4
          8      > RETURN                                                   ~5
   31     9*     > RETURN                                                   null

End of function valid

End of class values.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.34 ms | 1408 KiB | 23 Q