3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Person { protected $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } class Business { // adding Staff class to Business public function __construct(Staff $staff) { $this->staff = $staff; } // manual hire(adding Person to Staff) public function hire(Person $person) { // add to staff $this->staff->add($person); } // fetch members public function getStaffMembers() { return $this->staff->members(); } } class Staff { // adding people from Person class to "member" variable protected $members = []; public function __construct($members = []) { $this->members = $members; } // adding person to members public function add(Person $person) { $this->members[] = $person; } public function members() { return $this->members; } } // you can also create an array with this method $bros = [ 'Bro', 'Zdenko', 'Miljan', 'Kesten' ]; // pretty simple to understand this part $employees = new Person([$bros]); $staff = new Staff([$employees]); $business = new Business($staff); //var_dump($business->getStaffMembers()); // or the print_r, it doesn't matter //print_r($business->getStaffMembers()); /* You have an array of members now, if you'd like to utilize this array * you could iterate over it and echo each member, within a foreach loop * */ $membersArray = $business->getStaffMembers(); foreach($membersArray as $obj){ print_r($obj); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/VAcLl
function name:  (null)
number of ops:  26
compiled vars:  !0 = $bros, !1 = $employees, !2 = $staff, !3 = $business, !4 = $membersArray, !5 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   ASSIGN                                                   !0, <array>
   74     1        NEW                                              $7      'Person'
          2        INIT_ARRAY                                       ~8      !0
          3        SEND_VAL_EX                                              ~8
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $7
   76     6        NEW                                              $11     'Staff'
          7        INIT_ARRAY                                       ~12     !1
          8        SEND_VAL_EX                                              ~12
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $11
   78    11        NEW                                              $15     'Business'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !3, $15
   89    15        INIT_METHOD_CALL                                         !3, 'getStaffMembers'
         16        DO_FCALL                                      0  $18     
         17        ASSIGN                                                   !4, $18
   91    18      > FE_RESET_R                                       $20     !4, ->24
         19    > > FE_FETCH_R                                               $20, !5, ->24
   92    20    >   INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !5
         22        DO_ICALL                                                 
   91    23      > JMP                                                      ->19
         24    >   FE_FREE                                                  $20
   93    25      > RETURN                                                   1

Class Person:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAcLl
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   11     3      > 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/VAcLl
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

End of class Person.

Class Business:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAcLl
function name:  __construct
number of ops:  4
compiled vars:  !0 = $staff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        ASSIGN_OBJ                                               'staff'
          2        OP_DATA                                                  !0
   25     3      > RETURN                                                   null

End of function __construct

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

End of function hire

Function getstaffmembers:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAcLl
function name:  getStaffMembers
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~0      'staff'
          1        INIT_METHOD_CALL                                         ~0, 'members'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   38     4*     > RETURN                                                   null

End of function getstaffmembers

End of class Business.

Class Staff:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAcLl
function name:  __construct
number of ops:  4
compiled vars:  !0 = $members
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV_INIT                                        !0      <array>
   48     1        ASSIGN_OBJ                                               'members'
          2        OP_DATA                                                  !0
   49     3      > RETURN                                                   null

End of function __construct

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAcLl
function name:  add
number of ops:  5
compiled vars:  !0 = $person
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   54     1        FETCH_OBJ_W                                      $1      'members'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   55     4      > RETURN                                                   null

End of function add

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

End of function members

End of class Staff.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.26 ms | 1404 KiB | 15 Q