- var_dump: documentation ( source)
<?php
function setPrevious(Throwable $e, Throwable $previous): Throwable
{
try {
try {
throw $previous;
} finally {
throw $e;
}
} catch (Throwable $e) {
return $e;
}
}
class SimpleException extends Exception
{
public function __construct($message)
{
parent::__construct($message);
}
}
$a = new SimpleException('A');
$b = new SimpleException('B');
$c = new SimpleException('C');
setPrevious($a, $b);
setPrevious($a, $c);
$e = $a;
do {
var_dump($e->getMessage());
} while ($e = $e->getPrevious());