PHP debug_print_backtrace - Syntax
debug_print_backtrace([int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, [int $limit = 0]]): void
The PHP debug_print_backtrace() function is used to generate and print a backtrace with the information about where the call was initially triggered from the main source.
debug_print_backtrace([int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, [int $limit = 0]]): void
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. |
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_print_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
debug_print_backtrace();
}
}
$obj = new HelloWorld();
$obj->greetings();
Print the brack trace for the private class method printMessage() using php debug_print_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
debug_print_backtrace();
}
}
$obj = new HelloWorld();
$obj->greetings("John");
Print the brack trace for the class method greetings() using php debug_print_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
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
}
$obj = new HelloWorld();
$obj->greetings("John");
Print the brack trace for the class method greetings() using php debug_print_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
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
}
}
$obj = new HelloWorld();
$obj->greetings("John");