<?php class nasz_iterator implements Iterator{ private $i; private $obj; public function __construct($obiekt){ $this -> obj = $obiekt; $this -> i = 0; } // end __construct(); $this -> i = 0; } // end rewind(); public function valid(){ } // end valid(); return $this -> i; } // end key(); return $this -> obj -> get_item($this -> i); } // end current(); $this -> i++; } // end next(); } class x_file implements IteratorAggregate{ protected $plik; public function __construct($plik){ }else{ } } // end __construct(); public function getIterator(){ return new nasz_iterator($this); } // end getIterator(); public function get_item($i){ } // end get_item(); } // end key_exists(); } class x_list extends x_file{ public function __construct(){ } // end __construct(); public function add($item){ $this -> plik[] = $item; } // end add(); } $plix = new x_file('words.txt'); foreach($plix as $lnum => $linia){ } $lista = new x_list; $lista -> add('pozycja 1'); $lista -> add('pozycja 2'); $lista -> add('pozycja 3'); foreach($lista as $id => $pozycja){ } ?>
Mam tu przykład.I nie rozumiem dlaczego po uruchomieniu klasy x_file .Pierw uruchamia się metoda getIterator,potem key_exists a potem get_item.Dlaczego akurat w tej kolejności? Proszę o dokładne wytłumaczenie.Ponieważ w manualu nie pisze dokładnie dlaczego tak się to uruchamia.Nie rozumiem poprostu tego,
dlaczego w takiej kolejności się uruchamiają funkcje a nie w innej