Can you format your code by adding ``` on the line before and after the code.
Can you also show the staff class? My guess the error is in that
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm new to OOP PHP and have been following Laracasts OOP Bootcamp. I have reached a certain part of the tutorial where I'm having trouble. I have the following file (ignore that conventions were not followed, as it is the learning phase):
public function members() { return $this->members; } }
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();
}
}
$jeffrey = new Person('Jeffrey Way');
$staff = new Staff([$jeffrey]);
$laracasts = new Business($staff); $laracasts->hire(new Person('Jane Doe'));
var_dump($laracasts->getStaffMembers());
Unfortunately, the var_dump is only giving me one staff member:
array(1) { [0]=> object(Person)#4 (1) { ["name":protected]=> string(8) "Jane Doe" } }
I have tried adding [] to the line $this->members = $members; under Staff class but it's still giving me the same output. I've also double checked the files, I should be expecting two members instead of one.
Can someone tell me where I went wrong?
Please or to participate in this conversation.