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(){ $this->_keys = array(); foreach ($this->_data as $k => $v){ $this->_keys[] = $k; } $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 < 1000; $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/WDrS7
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'
   35     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
   37     7        ASSIGN                                                   !1, 0
          8      > JMP                                                      ->19
   38     9    > > FE_RESET_R                                       $10     !0, ->17
         10    > > FE_FETCH_R                                       ~11     $10, !2, ->17
         11    >   ASSIGN                                                   !3, ~11
   39    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !3
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   38    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $10
   37    18        PRE_INC                                                  !1
         19    >   IS_SMALLER                                               !1, 1000
         20      > JMPNZ                                                    ~15, ->9
   41    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/WDrS7
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/WDrS7
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/WDrS7
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/WDrS7
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 = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/WDrS7
function name:  rewind
number of ops:  18
compiled vars:  !0 = $v, !1 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN_OBJ                                               '_keys'
          1        OP_DATA                                                  <array>
   22     2        FETCH_OBJ_R                                      ~3      '_data'
          3      > FE_RESET_R                                       $4      ~3, ->10
          4    > > FE_FETCH_R                                       ~5      $4, !0, ->10
          5    >   ASSIGN                                                   !1, ~5
   23     6        FETCH_OBJ_W                                      $7      '_keys'
          7        ASSIGN_DIM                                               $7
          8        OP_DATA                                                  !1
   22     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $4
   25    11        INIT_FCALL                                               'reset'
         12        FETCH_OBJ_W                                      $10     '_keys'
         13        SEND_REF                                                 $10
         14        DO_ICALL                                         $11     
         15        ASSIGN_OBJ                                               '_key'
         16        OP_DATA                                                  $11
   26    17      > 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/WDrS7
function name:  valid
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      '_key'
          1        TYPE_CHECK                                    4          ~0
          2      > JMPZ                                                     ~1, ->4
   29     3    > > RETURN                                                   <false>
   31     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
   32     9*     > RETURN                                                   null

End of function valid

End of class values.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.65 ms | 1404 KiB | 19 Q