3v4l.org

run code in 300+ PHP versions simultaneously
<?php // класс хранилища данных, реализующий интерфейс Iterator class Registry implements Iterator { // массив, в котором хранятся настройки private $options = []; // возвращает текущий элемент public function current() { return current($this -> options); } // возвращает ключ текущего элемента public function key() { return key($this -> options); } // передвигаемся вперед на один элемент public function next() { next($this -> options); } // возвращает указатель на начало массива // фактически мы начинаем считать заново с нуля public function rewind() { reset($this -> options); } // проверяет, достигли ли мы конца массива public function valid() { return current($this -> options) !== false; } // метод для добавления настройки в хранилище public function set($option, $value) { $this -> options[$option] = $value; return $this; } // метод для получения настройки из хранилища public function get($option) { return $this -> options[$option]; } } // создали объект $reg = new Registry(); // добавили настройки $reg -> set("DS",DIRECTORY_SEPARATOR) -> set("APP_HOME", '.') -> set("AUTO_RELOAD",true); // и прошлись по настройкам. // обратите внимание - никаких массивов, только объект $reg foreach ( $reg as $option => $value ) { echo $option, " = ", $value, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/fMaTi
function name:  (null)
number of ops:  26
compiled vars:  !0 = $reg, !1 = $value, !2 = $option
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                            'registry'
   56     1        NEW                                              $3      'Registry'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   59     4        INIT_METHOD_CALL                                         !0, 'set'
          5        SEND_VAL_EX                                              'DS'
          6        SEND_VAL_EX                                              '%2F'
          7        DO_FCALL                                      0  $6      
   60     8        INIT_METHOD_CALL                                         $6, 'set'
          9        SEND_VAL_EX                                              'APP_HOME'
         10        SEND_VAL_EX                                              '.'
         11        DO_FCALL                                      0  $7      
   61    12        INIT_METHOD_CALL                                         $7, 'set'
         13        SEND_VAL_EX                                              'AUTO_RELOAD'
         14        SEND_VAL_EX                                              <true>
         15        DO_FCALL                                      0          
   65    16      > FE_RESET_R                                       $9      !0, ->24
         17    > > FE_FETCH_R                                       ~10     $9, !1, ->24
         18    >   ASSIGN                                                   !2, ~10
   66    19        ECHO                                                     !2
         20        ECHO                                                     '+%3D+'
         21        ECHO                                                     !1
         22        ECHO                                                     '%0A'
   65    23      > JMP                                                      ->17
         24    >   FE_FREE                                                  $9
   67    25      > RETURN                                                   1

Class Registry:
Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fMaTi
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~0      'options'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   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/fMaTi
function name:  key
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~0      'options'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   19     5*     > 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/fMaTi
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $0      'options'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                                 
   26     4      > RETURN                                                   null

End of function next

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fMaTi
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'reset'
          1        FETCH_OBJ_W                                      $0      'options'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                                 
   33     4      > 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/fMaTi
function name:  valid
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~0      'options'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        TYPE_CHECK                                  1018  ~2      $1
          5      > RETURN                                                   ~2
   39     6*     > RETURN                                                   null

End of function valid

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fMaTi
function name:  set
number of ops:  8
compiled vars:  !0 = $option, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2        FETCH_OBJ_W                                      $2      'options'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   45     5        FETCH_THIS                                       ~4      
          6      > RETURN                                                   ~4
   46     7*     > RETURN                                                   null

End of function set

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fMaTi
function name:  get
number of ops:  5
compiled vars:  !0 = $option
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        FETCH_OBJ_R                                      ~1      'options'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   52     4*     > RETURN                                                   null

End of function get

End of class Registry.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.76 ms | 1404 KiB | 21 Q