Ejemplo n.º 1
0
    }
    public function add(Student $student)
    {
        if (!$this->contains($student)) {
            $this->students[] = $student;
        }
    }
    public function contains(Student $student)
    {
        foreach ($this->students as $s) {
            if ($s->getId() == $student->getId()) {
                return true;
            }
        }
        return false;
    }
    public function getIterator()
    {
        return $this->students->getIterator();
    }
}
$students = new StudentList();
$students->add(new Student('01234123', 'Joe'));
$students->add(new Student('00000014', 'Bob'));
$students->add(new Student('00000014', 'Foo'));
foreach ($students as $student) {
    echo $student, "\n";
}
?>
===DONE===