Throwable::getPrevious

(PHP 7, PHP 8)

Throwable::getPreviousLiefert das vorherige Throwable

Beschreibung

public Throwable::getPrevious(): ?Throwable

Gibt ein mögliches vorheriges Throwable zurück (z. B. eines, welches als drittes Argument an Exception::__construct() übergeben wurde).

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Gibt das vorherige Throwable zurück, wenn eines vorhanden ist, andernfalls null.

Siehe auch

add a note

User Contributed Notes 1 note

up
0
harry at upmind dot com
5 years ago
/**
* Gets sequential array of all previously-chained errors
*
* @param Throwable $error
*
* @return Throwable[]
*/
function getChain(Throwable $error) : array
{
$chain = [];

do {
$chain[] = $error;
} while ($error = $error->getPrevious());

return $chain;
}
To Top