next($this->_listePersonnes); } return $n; } public function &listePersonnes() { $reference = $this->_listePersonnes; return $reference; } } $D1 = new Description(18, 70); $D2 = new Description(6, 25); $P1 = new Personne('A', 'aa', $D1); $P2 = new Personne('B', 'bb', $D2); $Voiture = new Voiture(); $Voiture->ajouterPersonne($P1)->ajouterPersonne($P2); echo '<h1>On peut verifier si un objet est transversable</h1>'; if ($Voiture instanceof Traversable) { echo '<p>Voirture est transversable</p>'; } if (!$P1 instanceof Traversable) { echo '<p>Personne n\'est pas transversable</p>'; } echo '<h1>Foreach parcour les Personnes dans la voiture</h1>'; foreach ($Voiture as $cle => $Personne) { echo $Personne->nom() . ' age : ' . $Personne->description_age() . '<br />'; } echo '<h1>On peut creer un iterateur pour parcourrir voiture</h1>'; $ItAg = $Voiture->getIterator(); var_dump($ItAg->current()->nom()); $ItAg->next();