PHP code example of awesomite / stack-trace

1. Go to this page and download the library: Download awesomite/stack-trace library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awesomite / stack-trace example snippets




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);