asadlive84

Why Get Null Value?-[Solved]

May 17th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. class Person
  4. {
  5.     protected $name;
  6.  
  7.     public function __construct($name)
  8.     {
  9.         $this->name=$name;
  10.     }
  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.  
  35. class Staff
  36. {
  37.     protected $members=[];
  38.  
  39.     public function __construct($members=[])
  40.     {
  41.         $this->members[]=$members;
  42.     }
  43.  
  44.     public function add(Person $person)
  45.     {
  46.         $this->members[]=$person;
  47.     }
  48.  
  49.     public function members()
  50.     {
  51.         return $this->members;
  52.     }
  53. }
  54.  
  55. $asad=new Person('Asaduzzman Sohel');
  56.  
  57. $staff=new Staff([$asad]);
  58.  
  59. $business=new Business($staff);
  60.  
  61. $business->hire(new Person('SOhel'));
  62.  
  63. var_dump($staff);
Advertisement
Add Comment
Please, Sign In to add comment