How To Debug Execution Path in PHP…Equivalent of printStackTrace() in Java
By Angsuman Chakraborty, Gaea News NetworkThursday, March 1, 2007
While programming in PHP often you will find that a simple echo or log statement is not sufficient. You have found out where a problem is happening but you have no clue why it is executing that code in the first place. This is where execution path comes in handy. With a simple call you can display the whole execution path of the code so far, every function that was executed, in which file and in which line number. Isn’t that handy?
Use debug_print_backtrace() to print the full execution path of the code upto that point. You can also use debug_backtrace() which returns an associative array with the following data:
Possible returned elements from debug_backtrace()
Name | Type | Description |
---|---|---|
function | string |
The current function name. See also |
line | integer |
The current line number. See also __LINE__. |
file | string |
The current file name. See also __FILE__. |
class | string |
The current class name. See also |
type | string |
The current call type. If a method call, “->” is returned. If a static method call, “::” is returned. If a function call, nothing is returned. |
args | array |
If inside a function, this lists the functions arguments. If |