3v4l.org

run code in 300+ PHP versions simultaneously
<?php session_start(); $_SESSION['foo'] = 1; class SessionIterator implements \Iterator { /** * @var array list of keys in the map */ private $_keys; /** * @var mixed current key */ private $_key; /** * Constructor. */ public function __construct() { $this->_keys = array_keys($_SESSION ?? []); } /** * Rewinds internal array pointer. * This method is required by the interface [[\Iterator]]. */ #[\ReturnTypeWillChange] public function rewind() { $this->_key = reset($this->_keys); } /** * Returns the key of the current array element. * This method is required by the interface [[\Iterator]]. * @return mixed the key of the current array element */ #[\ReturnTypeWillChange] public function key() { return $this->_key; } /** * Returns the current array element. * This method is required by the interface [[\Iterator]]. * @return mixed the current array element */ #[\ReturnTypeWillChange] public function current() { return isset($_SESSION[$this->_key]) ? $_SESSION[$this->_key] : null; } /** * Moves the internal pointer to the next array element. * This method is required by the interface [[\Iterator]]. */ #[\ReturnTypeWillChange] public function next() { do { $this->_key = next($this->_keys); } while (!isset($_SESSION[$this->_key]) && $this->_key !== false); } /** * Returns whether there is an element at current position. * This method is required by the interface [[\Iterator]]. * @return bool */ #[\ReturnTypeWillChange] public function valid() { return $this->_key !== false; } } $si = new SessionIterator(); foreach ($si as $key => $value) { var_dump($key, $value); }
Finding entry points
Branch analysis from position: 0
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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/7ldOG
function name:  (null)
number of ops:  19
compiled vars:  !0 = $si, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'session_start'
          1        DO_ICALL                                                 
    4     2        FETCH_W                      global              $4      '_SESSION'
          3        ASSIGN_DIM                                               $4, 'foo'
          4        OP_DATA                                                  1
    6     5        DECLARE_CLASS                                            'sessioniterator'
   82     6        NEW                                              $6      'SessionIterator'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $6
   83     9      > FE_RESET_R                                       $9      !0, ->17
         10    > > FE_FETCH_R                                       ~10     $9, !1, ->17
         11    >   ASSIGN                                                   !2, ~10
   84    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
   83    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $9
   85    18      > RETURN                                                   1

Class SessionIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ldOG
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'array_keys'
          1        FETCH_IS                                         ~1      '_SESSION'
          2        COALESCE                                         ~2      ~1
          3        QM_ASSIGN                                        ~2      <array>
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN_OBJ                                               '_keys'
          7        OP_DATA                                                  $3
   24     8      > RETURN                                                   null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ldOG
function name:  rewind
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'reset'
          1        FETCH_OBJ_W                                      $1      '_keys'
          2        SEND_REF                                                 $1
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               '_key'
          5        OP_DATA                                                  $2
   34     6      > RETURN                                                   null

End of function rewind

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

End of function key

Function current:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ldOG
function name:  current
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~1      '_key'
          1        FETCH_IS                                         ~0      '_SESSION'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~0, ~1
          3      > JMPZ                                                     ~2, ->9
          4    >   FETCH_OBJ_R                                      ~4      '_key'
          5        FETCH_R                      global              ~3      '_SESSION'
          6        FETCH_DIM_R                                      ~5      ~3, ~4
          7        QM_ASSIGN                                        ~6      ~5
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~6      null
         10    > > RETURN                                                   ~6
   56    11*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 0
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 0
Branch analysis from position: 14
filename:       /in/7ldOG
function name:  next
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     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
   67     6        FETCH_OBJ_R                                      ~4      '_key'
          7        FETCH_IS                                         ~3      '_SESSION'
          8        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~3, ~4
          9        BOOL_NOT                                         ~6      ~5
         10      > JMPZ_EX                                          ~6      ~6, ->14
         11    >   FETCH_OBJ_R                                      ~7      '_key'
         12        TYPE_CHECK                                  1018  ~8      ~7
         13        BOOL                                             ~6      ~8
         14    > > JMPNZ                                                    ~6, ->0
   68    15    > > RETURN                                                   null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ldOG
function name:  valid
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   FETCH_OBJ_R                                      ~0      '_key'
          1        TYPE_CHECK                                  1018  ~1      ~0
          2      > RETURN                                                   ~1
   79     3*     > RETURN                                                   null

End of function valid

End of class SessionIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.86 ms | 1446 KiB | 18 Q