1. Go to this page and download the library: Download kba-team/php-backtrace 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/ */
kba-team / php-backtrace example snippets
kbATeam\PhpBacktrace\ClassicBacktrace;
class Foo {
public function __construct($a, $b)
{
$this->bar(true, 10.2);
}
public function bar($c, $d)
{
static::baz(404);
}
public static function baz($e)
{
echo 'Remove __DIR__:' . PHP_EOL;
echo ClassicBacktrace::classicString(null, __DIR__) . PHP_EOL;
}
}
new Foo('Hello', 'World');
kbATeam\PhpBacktrace\ClassicBacktrace;
class Foo {
public function __construct($a, $b)
{
$this->bar(true, 10.2);
}
public function bar($c, $d)
{
static::baz(404);
}
public static function baz($e)
{
echo 'Increase offset by 2 steps:' . PHP_EOL;
echo (new ClassicBacktrace(2))->getClassicString() . PHP_EOL;
}
}
new Foo('Hello', 'World');
kbATeam\PhpBacktrace\Backtrace;
class Foo {
public function __construct($a, $b)
{
$this->bar(true, 10.2);
}
public function bar($c, $d)
{
static::baz(404);
}
public static function baz($e)
{
echo 'Class and line of last trace step:' . PHP_EOL;
$trace = new Backtrace(null, __DIR__);
printf(
'class: %s, line: %u%s',
$trace->lastStep('class'),
$trace->lastStep('line'),
PHP_EOL
);
echo PHP_EOL . 'Function and params of trace step before the last:' . PHP_EOL;
printf(
'function: %s, params: %s%s',
$trace->getStep(1, 'function'),
implode(', ', $trace->getStep(1, 'args')),
PHP_EOL
);
}
}
new Foo('Hello', 'World');
Remove __DIR__:
#0 Foo::baz(404) called at [test.php:13]
#1 Foo->bar(true, 10.2) called at [test.php:9]
#2 Foo->__construct(Hello, World) called at [test.php:21]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.