PHP code example of mortenscheel / tracer

1. Go to this page and download the library: Download mortenscheel/tracer 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/ */

    

mortenscheel / tracer example snippets


use Scheel\Tracer\StackTrace;

// Get a full stack trace
$trace = StackTrace::getTrace();

// Access the first frame
$firstFrame = $trace->first();

// Convert to array for inspection
$frames = $trace->toArray();

use Scheel\Tracer\StackTrace;
use Scheel\Tracer\Frame;

// Ignore vendor frames
$trace = StackTrace::getTrace()->ignoreVendor();

// Ignore specific classes
$trace = StackTrace::getTrace()->ignoreClass(SomeClass::class);

// Ignore specific class methods
$trace = StackTrace::getTrace()->ignoreClass(SomeClass::class, 'methodName');

// Ignore specific files
$trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php');

// Ignore specific lines in files
$trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php', 123);

// Custom filtering using the filter method
$trace = StackTrace::getTrace()->filter(function (Frame $frame): bool {
    return $frame->class !== 'ClassToIgnore';
});

use Scheel\Tracer\StackTrace;

$frame = StackTrace::getTrace()->first();

// Get frame location as string
echo $frame->location(); // "/path/to/file.php:123"

// Convert frame to array
$frameData = $frame->toArray();
/*
[
    'file' => '/path/to/file.php',
    'line' => 123,
    'function' => 'methodName',
    'class' => 'ClassName',
    'type' => '::',
]
*/

// Generate editor links
echo $frame->editorLink(); // "phpstorm://open?file=/path/to/file.php&line=123"