Iterator::valid

(PHP 5, PHP 7, PHP 8)

Iterator::validPrüft, ob die aktuelle Position zulässig ist

Beschreibung

public 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.

add a note

User Contributed Notes 2 notes

up
9
seva dot lapsha at gmail dot com
14 years ago
If Iterator::valid() returns false, the foreach() loop will be terminated.
up
7
Voitcus at gmail dot com
11 years ago
If your class implements also ArrayAccess interface, you could use as valid() body

function valid(){
return $this->offsetExists($this->position);
}
To Top