Reputation: 494
I am trying to make a conditional PHP debugger tool, that, when called, will write certain steps in execution like a position in code which corresponds to a function or level.
I formed it as:
define("DEBUGGING", TRUE); //IF TRUE, TURNS ON CONDITIONAL CODE THAT RETURNS CODE FLOW
and
if (DEBUGGING) { echo "RETURN LINE OF CODE OR SOMETHING ELSE"; }
which I insert where needed.
Is there a better way to do this? I did turn all PHP warning levels ON, but that is not enough as I don't know which part of the code was executed due to redundant functions.
Thanks!
Upvotes: 0
Views: 77
Reputation: 21661
to get a stack trace easily
try{
throw new Exception();
}catch(Exception $e ){
echo $e->getTraceAsString();
}
This will give you a real nice stacktrace.
Upvotes: 0
Reputation: 13004
Instead of needlessly cluttering up your code you should just install Xdebug.
This will output full stack traces in HTML format when there is an error in your code.
Here is an output example I found via google:
Also, Xdebug provides remote debugging so that you can use a real debugger (I use PHPStorm) to step through your code.
Upvotes: 2