lordfireen / backtrace
OOP for backtrace
v1.0.0
2026-05-19 15:07 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^11.5
This package is not auto-updated.
Last update: 2026-05-19 20:29:18 UTC
README
Pack of classes for object-oriented backtrace.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
composer require lordfireen/backtrace
How to use
The use case is pretty simple:
$service = new \LF\Backtrace\BacktraceService();
$backtrace = $service->getFrames($limit, $options); // which is equivalent to debug_backtrace($options, $limit);
$frame = $backtrace[0]; // But instead of array we get object of LF\Backtrace\BacktaceFrame which is readonly class.
$frame->file; // is equivalent to debug_backtrace()[0]['file']
$frame->line; // is equivalent to debug_backtrace()[0]['line']
$frame->function; // is equivalent to debug_backtrace()[0]['function']
$frame->class; // is equivalent to debug_backtrace()[0]['class']
$frame->object; // is equivalent to debug_backtrace()[0]['object']
$frame->args; // is equivalent to debug_backtrace()[0]['args']
$type = $frame->type; // is equivalent to debug_backtrace()[0]['type'] and it's an enum LF\Backtrace\CallType
You could receive a single frame in any depth as follows:
function foo($service) {
echo $service->getSingleFrame(1)->function . ' & ';
echo $service->getSingleFrame(2)->function;
}
function bar($service) {
foo($service);
}
bar(new \LF\Backtrace\BacktraceService()); // foo & bar
The frame could return the caller name as follows:
$frame->getCallerName(); // Which could be `Class->method`, `Class::method` or `method`