mrmut
mrmut

Reputation: 494

How to make PHP debugging process?

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

Answers (2)

ArtisticPhoenix
ArtisticPhoenix

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

timclutton
timclutton

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:

Xdebug output example

Also, Xdebug provides remote debugging so that you can use a real debugger (I use PHPStorm) to step through your code.

Upvotes: 2

Related Questions