Kraken\Throwable\Exception::toStackString PHP Method

toStackString() public static method

Return Exception stack trace in string format.
public static toStackString ( Error | Exception $ex ) : string
$ex Error | Exception
return string
    public static function toStackString($ex)
    {
        $stack = [];
        $i = 0;
        $trace = static::toStackTrace($ex);
        $pad = strlen(count($trace)) > 2 ?: 2;
        foreach ($trace as $element) {
            $stack[] = "\t" . str_pad('' . $i, $pad, ' ', STR_PAD_LEFT) . '. ' . $element;
            ++$i;
        }
        return implode("\n", $stack);
    }

Usage Example

Example #1
0
 /**
  *
  */
 public function testStaticApiToStackString_ReturnsStackTraceAsString()
 {
     $prev = $this->createException('Previous');
     $ex = $this->createException('Exception', $prev);
     $this->assertStackString(Exception::toStackString($ex));
 }