src/Exception.php
final public static function toArray(Throwable $throwable, bool $traceAsString = false, int $depth = 512) : array
    {
        $result = [
            'type' => get_class($throwable),
            'message' => $throwable->getMessage(),
            'code' => $throwable->getCode(),
            'file' => $throwable->getFile(),
            'line' => $throwable->getLine(),
            'trace' => $traceAsString ? $throwable->getTraceAsString() : $throwable->getTrace(),
            'previous' => null,
        ];

        if ($throwable->getPrevious() !== null && --$depth) {
            $result['previous'] = self::toArray($throwable->getPrevious(), $traceAsString, $depth);
        }

        return $result;
    }
final public static function toArray(Throwable $throwable, bool $traceAsString = false, int $depth = 512) : array
    {
        $result = [
            'type' => get_class($throwable),
            'message' => $throwable->getMessage(),
            'code' => $throwable->getCode(),
            'file' => $throwable->getFile(),
            'line' => $throwable->getLine(),
            'trace' => $traceAsString ? $throwable->getTraceAsString() : $throwable->getTrace(),
            'previous' => null,
        ];

        if ($throwable->getPrevious() !== null && --$depth) {
            $result['previous'] = self::toArray($throwable->getPrevious(), $traceAsString, $depth);
        }

        return $result;
    }
final public static function toArray ( Throwable $ throwable , bool $ traceAsString = false , int $ depth = 512 ) : array { $ result = [ 'type' => get_class ( $ throwable ) , 'message' => $ throwable -> getMessage ( ) , 'code' => $ throwable -> getCode ( ) , 'file' => $ throwable -> getFile ( ) , 'line' => $ throwable -> getLine ( ) , 'trace' => $ traceAsString ? $ throwable -> getTraceAsString ( ) : $ throwable -> getTrace ( ) , 'previous' => null , ] ; if ( $ throwable -> getPrevious ( ) !== null && -- $ depth ) { $ result [ 'previous' ] = self :: toArray ( $ throwable -> getPrevious ( ) , $ traceAsString , $ depth ) ; } return $ result ; }
Converts the given Exception to an array.

@param Throwable $throwable     The exception to convert.
@param boolean   $traceAsString Flag to return the exception trace as a string or array.
@param integer   $depth         User specified recursion depth.

@return array
Converts the given Exception to an array .