Throwable::getPrevious

(PHP 7, PHP 8)

Throwable::getPreviousひとつ前の Throwable を返す

説明

public Throwable::getPrevious(): ?Throwable

ひとつ前の Throwable (たとえば Exception::__construct() の第三パラメータで指定したもの) を返します。

パラメータ

この関数にはパラメータはありません。

戻り値

ひとつ前の Throwable が存在すればそれを返します。 存在しない場合は null を返します。

参考

add a note

User Contributed Notes 1 note

up
0
harry at upmind dot com
6 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