asadlive84

Why Get Null Value?

May 17th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Person
  5. {
  6.     protected $name;
  7.  
  8.     public function __construct($name)
  9.     {
  10.         $this->name=$name;
  11.     }
  12. }
  13.  
  14. class Business
  15. {
  16.     protected $staff;
  17.  
  18.     public function __construct(Staff $staff)
  19.     {
  20.         $this->staff=$staff;
  21.     }
  22.  
  23.     public function hire(Person $person)
  24.     {
  25.         $this->staff->add($person);
  26.     }
  27.  
  28.     public function getStaffMembers()
  29.     {
  30.         $this->staff->members();
  31.     }
  32. }
  33.  
  34. class Staff
  35. {
  36.     protected $members=[];
  37.  
  38.     public function __construct($members=[])
  39.     {
  40.         $this->members=$members;
  41.     }
  42.  
  43.     public function add(Person $person)
  44.     {
  45.         $this->members=$person;
  46.     }
  47.  
  48.     public function members()
  49.     {
  50.         return $this->members;
  51.     }
  52. }
  53.  
  54.  
  55. $person=new Person('Sohel');
  56.  
  57. $staff=new Staff([$person]);
  58.  
  59. $business=new Business($staff);
  60.  
  61. $business->hire(new Person('ASad doee'));
  62.  
  63. var_dump($business->getStaffMembers());
  64.  
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment