简体   繁体   English

如何使PHP调试过程?

[英]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. 我正在尝试制作一个有条件的PHP调试器工具,该工具在被调用时将编写某些执行步骤,例如代码中与功能或级别相对应的位置。

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. 我确实打开了所有PHP警告级别,但这还不够,因为我不知道由于冗余功能而执行了代码的哪一部分。

Thanks! 谢谢!

Instead of needlessly cluttering up your code you should just install Xdebug . 不必不必要地弄乱代码,而应该安装Xdebug

This will output full stack traces in HTML format when there is an error in your code. 当您的代码有错误时,它将以HTML格式输出完整的堆栈跟踪。

Here is an output example I found via google: 这是我通过google找到的输出示例:

Xdebug输出示例

Also, Xdebug provides remote debugging so that you can use a real debugger (I use PHPStorm ) to step through your code. 另外,Xdebug提供了远程调试,因此您可以使用真正的调试器(我使用PHPStorm )来逐步执行代码。

to get a stack trace easily 轻松获得堆栈跟踪

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

This will give you a real nice stacktrace. 这将为您提供真正好的堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM