PHP debug_backtrace - Syntax
debug_backtrace([int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, [int $limit = 0]]): array
The PHP debug_backtrace() function is used to generate a backtrace and it returns the associative array with the information about where the call was initially triggered from the main source.
debug_backtrace([int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, [int $limit = 0]]): array
Constant $constant |
Specifies the constants either DEBUG_BACKTRACE_PROVIDE_OBJECT / DEBUG_BACKTRACE_IGNORE_ARGS by default it takes the argument DEBUG_BACKTRACE_PROVIDE_OBJECT. |
---|---|
int $limit |
Specifies the number of stack frames should be returned returned. By default 0, it returns all stack frames. |
Return array $result |
Returns an associative array with the information like function, line, file, class, object, type and arguments only if Success otherwise NULL. |
DEBUG_BACKTRACE_PROVIDE_OBJECT: It provides an additional information about the Object Argument and it has an integer value 1.
DEBUG_BACKTRACE_IGNORE_ARGS: It ignores the argument information to the output and it has an integer value 2.
Print the brack trace for the class method greetings() using php debug_backtrace with a default parameter DEBUG_BACKTRACE_PROVIDE_OBJECT and a default limit 0 (i.e. it returns all stack frames). It will print all the information about where the call was initially triggered from the main source.
<?php
class HelloWorld {
public function greetings() {
echo("Hello World \n");
// Back Tracing Operation
// with DEBUG_BACKTRACE_PROVIDE_OBJECT and limit 0
$trace_array = debug_backtrace();
print_r($trace_array);
}
}
$obj = new HelloWorld();
$obj->greetings();
Print the brack trace for the private class method printMessage() using php debug_backtrace with a default parameter DEBUG_BACKTRACE_PROVIDE_OBJECT and a default limit 0 (i.e. it returns all stack frames). It will print all the information about where the call was initially triggered from the main source.
<?php
class HelloWorld {
public function greetings($person) {
$message = "Hello " . $person;
// Calling a private method to print the message
$this->printMessage($message);
}
private function printMessage($message) {
echo($message . "\n");
// Back Tracing Operation
// with DEBUG_BACKTRACE_PROVIDE_OBJECT and limit 0
$trace_array = debug_backtrace();
print_r($trace_array);
}
}
$obj = new HelloWorld();
$obj->greetings("John");
Print the brack trace for the class method greetings() using php debug_backtrace with a parameter DEBUG_BACKTRACE_IGNORE_ARGS and a default limit 0 (i.e. it returns all stack frames). It will print all the information about where the call was initially triggered from the main source.
<?php
class HelloWorld {
public function greetings($person) {
$message = "Hello " . $person;
// Calling a private method to print the message
$this->printMessage($message);
}
private function printMessage($message) {
echo($message . "\n");
// Back Tracing Operation
// with DEBUG_BACKTRACE_IGNORE_ARGS and limit 0
$trace_array = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
print_r($trace_array);
}
}
$obj = new HelloWorld();
$obj->greetings("John");
Print the brack trace for the class method greetings() using php debug_backtrace with a parameter DEBUG_BACKTRACE_IGNORE_ARGS and a limit 1 (i.e. it returns only one stack frames). It will print first ancestors of the information about where the call was initially triggered from the main source.
<?php
class HelloWorld {
public function greetings($person) {
$message = "Hello " . $person;
// Calling a private method to print the message
$this->printMessage($message);
}
private function printMessage($message) {
echo($message . "\n");
// Back Tracing Operation
// with DEBUG_BACKTRACE_IGNORE_ARGS and limit 1
$trace_array = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
print_r($trace_array);
}
}
$obj = new HelloWorld();
$obj->greetings("John");