0

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!

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! Does X-Debug also return results for execution of good code? - The reason I ask, is because I have a redundant functions that account to various fail situations, and account for one another. That means that if I don't know which part of the code was precisely executed, I can not precisely know is the code really works or not. Thanks.
use try catch and throw an exception
I don't really understand what you mean. Surely the result of executing good code is that your application works? If you want to confirm the code execution path you can add something like echo __FILE__ . ': ' . __LINE__; in various places. This will output the exact location where it is placed. But this would be more easily done by stepping through with a real debugger.
I think the OP wants a stacktrace, so they can check that redundant code is not being executed. I suggest using exceptions to handle your errors.
In the end, I ended adding echo FILE comments. I needed to check for each contingency on a working code. Nothing else I tried worked. Thanks.
0

to get a stack trace easily

try{
    throw new Exception();
}catch(Exception $e ){
    echo $e->getTraceAsString();
}

This will give you a real nice stacktrace.

1 Comment

Thanks; will implement!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.