surada4000
2 months ago
568
6
General

OOP Bootcamp - lesson 5

Posted 2 months ago by surada4000
<?php
Class Person {
    protected $name;

    public function __construct($name)
    {
        $this->name = $name;
    }
}

Class Business {

    protected $staff;

    public function __construct(Staff $staff)
    {
        $this->staff = $staff;
    }

    public function hire(Person $person)
    {
        $this->staff->add($person);   
    }

    public function getStaffMembers()
    {
        return $this->staff->members();
    }
}

Class Staff {
    protected $members = [];

    protected function __construct($members = [])
    {
        $this->members = $members;
    }

    public function add(Person $person)
    {
        $this->members[] = $person;
    }

    public function members()
    {
        return $this->staff->members();
    }
}

$loi = new Person('loi dep trai');

$staff = new Staff([$loi]);

$laracast = new Business($staff);  

$laracast->hire(new Person('I love my live'));

var_dump($laracast->getStaffMembers());
?>

Call to protected Staff::__construct() $staff = new Staff return the error .How to fix it ? Thanks

Please sign in or create an account to participate in this conversation.