3v4l.org

run code in 300+ PHP versions simultaneously
<?php // класс для хранения данных о сотруднике class Employee { private $_name; private $_departament; public function __construct($name, $departament) { $this->_name = $name; $this->_departament = $departament; } public function getName() { return $this->_name; } public function getDepartament() { return $this->_departament; } } // класс для хранения списка объектов class ObjectList { private $_objList; public function __construct() { $this->free(); } /** *чтобы не скучать! */ public function free() { $this->_objList = array(); } public function count() { return count($this->_objList); } public function add($obj) { array_push($this->_objList, $obj); } public function remove($obj) { $k = array_search( $obj, $this->_objList, true ); if ( $k !== false ) { unset( $this->_objList[$k] ); } } public function get($index) { return $this->_objList[$index]; } public function set($index, $obj) { $this->_objList[$index] = $obj; } } // класс для хранения сотрудников class EmployeeList { // объект класса "список объектов" private $_employeersList; public function __construct(){ // создаём объект методы которого будем делегировать $this->_employeersList = new ObjectList; } public function getEmployer($index) { return $this->_employeersList->get($index); } public function setEmployer($index, Employee $objEmployer) { $this->_employeersList->set($index, $objEmployer); } public function __destruct() { $this->_employeersList->free(); } public function add(Employee $objEmployer) { $this->_employeersList->add($objEmployer); } public function remove(Employee $objEmployer) { $this->_employeersList->remove($objEmployer); } // последовательный поиск сотрудника по имени // через аргумент $offset можно задавать позицию с которой вести поиск. // если сотрудник не найден вернёт значение меньше ноля (-1) public function getIndexByName($name, $offset=0) { $result = -1; // предполагаем, что его нету в списке $cnt = $this->_employeersList->count(); for ($i = $offset; $i < $cnt; $i++) { if ( !strcmp( $name, $this->_employeersList->get($i)->getName() ) ) { $result = $i; break; } } return $result; } } $obj1 = new Employee("Танасийчук Степан", "web студия"); $obj2 = new Employee("Кусый Назар", "web студия"); $obj3 = new Employee("Сорока Орест", "web студия"); $objList = new EmployeeList(); $objList->add($obj1); $objList->add($obj2); $objList->add($obj3); echo "<pre>"; print_r($objList); echo "<hr>"; $index = $objList->getIndexByName("Кусый Назар"); $obj4 = $objList->getEmployer($index); print_r($obj4); echo "<hr>"; $objList->setEmployer(2, $obj4); print_r($objList); echo "</pre>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  (null)
number of ops:  53
compiled vars:  !0 = $obj1, !1 = $obj2, !2 = $obj3, !3 = $objList, !4 = $index, !5 = $obj4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   NEW                                              $6      'Employee'
          1        SEND_VAL_EX                                              '%D0%A2%D0%B0%D0%BD%D0%B0%D1%81%D0%B8%D0%B9%D1%87%D1%83%D0%BA+%D0%A1%D1%82%D0%B5%D0%BF%D0%B0%D0%BD'
          2        SEND_VAL_EX                                              'web+%D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $6
  110     5        NEW                                              $9      'Employee'
          6        SEND_VAL_EX                                              '%D0%9A%D1%83%D1%81%D1%8B%D0%B9+%D0%9D%D0%B0%D0%B7%D0%B0%D1%80'
          7        SEND_VAL_EX                                              'web+%D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $9
  111    10        NEW                                              $12     'Employee'
         11        SEND_VAL_EX                                              '%D0%A1%D0%BE%D1%80%D0%BE%D0%BA%D0%B0+%D0%9E%D1%80%D0%B5%D1%81%D1%82'
         12        SEND_VAL_EX                                              'web+%D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !2, $12
  113    15        NEW                                              $15     'EmployeeList'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !3, $15
  114    18        INIT_METHOD_CALL                                         !3, 'add'
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0          
  115    21        INIT_METHOD_CALL                                         !3, 'add'
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0          
  116    24        INIT_METHOD_CALL                                         !3, 'add'
         25        SEND_VAR_EX                                              !2
         26        DO_FCALL                                      0          
  118    27        ECHO                                                     '%3Cpre%3E'
  119    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                                 
  121    31        ECHO                                                     '%3Chr%3E'
  123    32        INIT_METHOD_CALL                                         !3, 'getIndexByName'
         33        SEND_VAL_EX                                              '%D0%9A%D1%83%D1%81%D1%8B%D0%B9+%D0%9D%D0%B0%D0%B7%D0%B0%D1%80'
         34        DO_FCALL                                      0  $22     
         35        ASSIGN                                                   !4, $22
  124    36        INIT_METHOD_CALL                                         !3, 'getEmployer'
         37        SEND_VAR_EX                                              !4
         38        DO_FCALL                                      0  $24     
         39        ASSIGN                                                   !5, $24
  125    40        INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !5
         42        DO_ICALL                                                 
  127    43        ECHO                                                     '%3Chr%3E'
  129    44        INIT_METHOD_CALL                                         !3, 'setEmployer'
         45        SEND_VAL_EX                                              2
         46        SEND_VAR_EX                                              !5
         47        DO_FCALL                                      0          
  130    48        INIT_FCALL                                               'print_r'
         49        SEND_VAR                                                 !3
         50        DO_ICALL                                                 
  131    51        ECHO                                                     '%3C%2Fpre%3E'
         52      > RETURN                                                   1

Class Employee:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  __construct
number of ops:  7
compiled vars:  !0 = $name, !1 = $departament
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN_OBJ                                               '_name'
          3        OP_DATA                                                  !0
   11     4        ASSIGN_OBJ                                               '_departament'
          5        OP_DATA                                                  !1
   12     6      > RETURN                                                   null

End of function __construct

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

End of function getname

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

End of function getdepartament

End of class Employee.

Class ObjectList:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_METHOD_CALL                                         'free'
          1        DO_FCALL                                      0          
   30     2      > RETURN                                                   null

End of function __construct

Function free:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  free
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN_OBJ                                               '_objList'
          1        OP_DATA                                                  <array>
   36     2      > RETURN                                                   null

End of function free

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  count
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~0      '_objList'
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   40     3*     > RETURN                                                   null

End of function count

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  add
number of ops:  7
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'array_push'
          2        FETCH_OBJ_W                                      $1      '_objList'
          3        SEND_REF                                                 $1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   44     6      > RETURN                                                   null

End of function add

Function remove:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/bijCY
function name:  remove
number of ops:  13
compiled vars:  !0 = $obj, !1 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        INIT_FCALL                                               'array_search'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~2      '_objList'
          4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   48     8        TYPE_CHECK                                  1018          !1
          9      > JMPZ                                                     ~5, ->12
   49    10    >   FETCH_OBJ_UNSET                                  $6      '_objList'
         11        UNSET_DIM                                                $6, !1
   51    12    > > RETURN                                                   null

End of function remove

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

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  set
number of ops:  6
compiled vars:  !0 = $index, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   58     2        FETCH_OBJ_W                                      $2      '_objList'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   59     5      > RETURN                                                   null

End of function set

End of class ObjectList.

Class EmployeeList:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   NEW                                              $1      'ObjectList'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               '_employeersList'
          3        OP_DATA                                                  $1
   71     4      > RETURN                                                   null

End of function __construct

Function getemployer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  getEmployer
number of ops:  7
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   74     1        FETCH_OBJ_R                                      ~1      '_employeersList'
          2        INIT_METHOD_CALL                                         ~1, 'get'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   75     6*     > RETURN                                                   null

End of function getemployer

Function setemployer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  setEmployer
number of ops:  8
compiled vars:  !0 = $index, !1 = $objEmployer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   78     2        FETCH_OBJ_R                                      ~2      '_employeersList'
          3        INIT_METHOD_CALL                                         ~2, 'set'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   79     7      > RETURN                                                   null

End of function setemployer

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  __destruct
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   FETCH_OBJ_R                                      ~0      '_employeersList'
          1        INIT_METHOD_CALL                                         ~0, 'free'
          2        DO_FCALL                                      0          
   83     3      > RETURN                                                   null

End of function __destruct

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  add
number of ops:  6
compiled vars:  !0 = $objEmployer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
   86     1        FETCH_OBJ_R                                      ~1      '_employeersList'
          2        INIT_METHOD_CALL                                         ~1, 'add'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   87     5      > RETURN                                                   null

End of function add

Function remove:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bijCY
function name:  remove
number of ops:  6
compiled vars:  !0 = $objEmployer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
   90     1        FETCH_OBJ_R                                      ~1      '_employeersList'
          2        INIT_METHOD_CALL                                         ~1, 'remove'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   91     5      > RETURN                                                   null

End of function remove

Function getindexbyname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 9
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 9
Branch analysis from position: 26
Branch analysis from position: 9
filename:       /in/bijCY
function name:  getIndexByName
number of ops:  28
compiled vars:  !0 = $name, !1 = $offset, !2 = $result, !3 = $cnt, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   97     2        ASSIGN                                                   !2, -1
   98     3        FETCH_OBJ_R                                      ~6      '_employeersList'
          4        INIT_METHOD_CALL                                         ~6, 'count'
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !3, $7
   99     7        ASSIGN                                                   !4, !1
          8      > JMP                                                      ->24
  100     9    >   INIT_FCALL                                               'strcmp'
         10        SEND_VAR                                                 !0
         11        FETCH_OBJ_R                                      ~10     '_employeersList'
         12        INIT_METHOD_CALL                                         ~10, 'get'
         13        SEND_VAR_EX                                              !4
         14        DO_FCALL                                      0  $11     
         15        INIT_METHOD_CALL                                         $11, 'getName'
         16        DO_FCALL                                      0  $12     
         17        SEND_VAR                                                 $12
         18        DO_ICALL                                         $13     
         19        BOOL_NOT                                         ~14     $13
         20      > JMPZ                                                     ~14, ->23
  101    21    >   ASSIGN                                                   !2, !4
  102    22      > JMP                                                      ->26
   99    23    >   PRE_INC                                                  !4
         24    >   IS_SMALLER                                               !4, !3
         25      > JMPNZ                                                    ~17, ->9
  105    26    > > RETURN                                                   !2
  106    27*     > RETURN                                                   null

End of function getindexbyname

End of class EmployeeList.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.63 ms | 1416 KiB | 21 Q