parent root
PHP: Throwable::getPrevious - Manual
PHP 7.2.23 Release Announcement

Throwable::getPrevious

(PHP 7)

Throwable::getPreviousReturns the previous Throwable

Description

abstract public Throwable::getPrevious ( void ) : Throwable

Returns any previous Throwable (for example, one provided as the third parameter to Exception::__construct()).

Parameters

This function has no parameters.

Return Values

Returns the previous Throwable if available, or NULL otherwise.

See Also

add a noteadd a note

User Contributed Notes 1 note

up
0
harry at upmind dot com
10 months 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
parent root