2024 年日本 PHP 研討會

Throwable::getPrevious

(PHP 7, PHP 8)

Throwable::getPrevious返回前一個 Throwable

說明

public Throwable::getPrevious(): ?Throwable

傳回任何先前的 Throwable(例如,作為 Exception::__construct() 的第三個參數提供的)。

參數

此函式沒有參數。

傳回值

如果有的話,傳回先前的 Throwable,否則傳回 null

另請參閱

新增註解

使用者貢獻的註解 1 則註解

0
harry at upmind dot com
6 年前
/**
* 取得所有先前鏈式錯誤的序列陣列
*
* @param Throwable $error
*
* @return Throwable[]
*/
function getChain(Throwable $error) : array
{
$chain = [];

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

return $chain;
}
To Top