awesomite/stack-trace

The wrapper for debug_backtrace() function

v1.3.1 2018-10-11 16:12 UTC

README

Codacy Badge Coverage Status Build Status

Abstract layer for debug_backtrace() function. This library allows you to serialize whole stack trace including variables. It handles all types of data, including resources.

Usage

See documentation.

<?php

use Awesomite\StackTrace\StackTraceFactory;
use Awesomite\StackTrace\Steps\StepInterface;
use Awesomite\StackTrace\SourceCode\PlaceInCodeInterface;

$factory = new StackTraceFactory();
$stackTrace = $factory->create();
foreach ($stackTrace as $step) {
    /** @var StepInterface $step */
    
    $function = $step->getCalledFunction()->getName();
    echo "Function {$function}";
    
    if ($step->hasPlaceInCode()) {
        /** @var PlaceInCodeInterface $placeInCode */
        $placeInCode = $step->getPlaceInCode();
        $fileName = $placeInCode->getFileName();
        $line = $placeInCode->getLineNumber();
        $function = $step->getCalledFunction()->getName();
        echo " is called from {$fileName}:{$line}";
    }
    
    echo "\n";
}

$data = serialize($stackTrace);
$unserializedStackTrace = unserialize($data);

Installation

composer require awesomite/stack-trace

Versioning

The version numbers follow the Semantic Versioning 2.0.0 scheme. Read more about backward compatibility.

Examples

See more examples.

License

This library is released under the MIT license.