- array_push: documentation ( source)
- var_dump: documentation ( source)
<?php
class Student
{
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
class Secretary
{
private $students = [];
public function addStudent(Student $s): Secretary
{
array_push($this->students, $s);
return $this;
}
public function getStudents(): array
{
return $this->students;
}
}
$s = new Secretary();
$s->addStudent(new Student('Foo'));
var_dump($s->getStudents());