phpday 2027 - Call for Papers

Iterator::valid

(PHP 5, PHP 7, PHP 8)

Iterator::valid — Prüft, ob die aktuelle Position zulässig ist

Beschreibung

public function Iterator::valid(): bool

Diese Methode wird nach Iterator::rewind() und Iterator::next() aufgerufen, um zu prüfen, ob die aktuelle Position zulässig ist.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Der Rückgabewert wird in den Typ bool umgewandelt und dann ausgewertet. Gibt bei Erfolg true zurück. Bei einem Fehler wird false zurückgegeben.

User Contributed Notes 2 notes

up
10
Voitcus at gmail dot com
13 years ago
If your class implements also ArrayAccess interface, you could use as valid() body

function valid(){    
   return $this->offsetExists($this->position);
}
up
6
seva dot lapsha at gmail dot com
17 years ago
If Iterator::valid() returns false, the foreach() loop will be terminated.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top