class Fibonacci implements Iterator {
   protected $previous = 1;
   protected $current = 0;
   protected $key = 0;
  
   public function current() {
      return $this->current;
   }
  
   public function key() {
      return $this->key;
   }
  
   public function next() {
      $this->key++;
      $tmp = $this->current;
      $this->current += $this->previous;
      $this->previous = $tmp;
   }
  
   public function rewind() {
      $this->key = 0;
      $this->previous = 1;
      $this->current = 0;
   }
  
   public function valid() {
      return true;
   }
}

$it = new Fibonacci();
$it = new LimitIterator($it, 0, 15);
foreach ($it as $num) {
   print $num . " " . PHP_EOL;
}
print PHP_EOL;
