While working on one of my PHP project I got a function debug_backtrace() at the start of code file as <?php debug_backtrace() || die ("Direct access not permitted"); ?> .
While studding on it I got some explanation that it works as:
Debugging PHP issues in a Drupal website can be anything from quick and easy to seriously problematic. PHP includes a debugging function called debug_backtrace , which will print out the chain of code that leads up to the point where the backtrace function is called.
And When I use var_dump() with debug_backtrace() I got following result:
array(2) {
[0]=>
array(3) {
["file"]=>
string(61) "C:\xampp\htdocs\folder_name\templates\default\models\home.php"
["line"]=>
int(30)
["function"]=>
string(7) "include"
}
[1]=>
array(4) {
["file"]=>
string(37) "C:\xampp\htdocs\folder_name\index.php"
["line"]=>
int(146)
["args"]=>
array(1) {
[0]=>
string(61) "C:\xampp\htdocs\folder_name\templates\default\models\home.php"
}
["function"]=>
string(7) "include"
}
}
I didn't get that what debug_backtrace() function exactly work.
Please anyone explain is welcome. Thanks in advance.
Studied links:
debug_backtrace() from registered shutdown function in PHP
Debugging PHP Code with debug_backtrace
Giving a basic example...
Will output...
I hope this shows that all the
debug_backtracefunction does is return what has been called so far. So when you first callt1, it is simply a stack trace of the call tot1. The same for the start oft2, but whent2callst1, the trace lists the call tot2andt1.But also as you can see, that
debug_backtracefromStart..shows nothing, as there are no levels of code that have caused this trace to be printed.In your case it calls
debug_backtraceand uses theor die()to say 'ifdebug_backtracereturns nothing, thendie()'