} public function key() { return $this->key; } public function next() { if ($this->value === 0) { $this->value = 1; } else { $old = $this->value; $this->value += $this->sum; $this->sum = $old; } $this->key++; } public function valid() { return $this->value < PHP_INT_MAX; } } // print the Fibonacci numbers until PHP_INT_MAX foreach ($test = new Fibonacci() as $key => $value) { printf("%d) %d\n", $key, $value); } // print the first 10 Fibonacci's numbers $num = new Fibonacci(); for ($i = 0; $i < 10; $i++) { printf("%d) %d\n", $i, $num->current()); $num->next(); }