在 PHP 函数末尾自动执行函数
我希望在每个函数的末尾调用自定义错误日志/调试函数。
示例:
- 我想调用
error_log(__METHOD__);
- 我想
echo $query;
- 显示执行时间等。
在每个函数的末尾用于调试目的,而不必每次都调用该自定义函数。
非常感谢。
i'm looking to call a custom error log/debug function at the end of each function.
example:
- i want to call
error_log(__METHOD__);
- I want to
echo $query;
- show execution time etc..
at the end of every function for debug purposes without having to call that customized function every time.
much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,请使用调试器/分析器,例如使用 XDebug 或 Zend 调试器。
有关两者的比较,请参阅
Use a Debugger/Profiler for this, e.g. use XDebug or Zend Debugger.
For a comparison of the two, see
经过多次 RTM 之后,我不得不使用
debug_backtrace();
,尽管它很昂贵。我是这样做的:
在每个函数的末尾我添加以下内容:
或者如果该函数有一个 SQL 查询:
输出通常在 php_error.log 中如下所示:
after much RTM i had to use
debug_backtrace();
even though it's expensive.here's how i did it:
and at the end of each function i add the following:
or if the function has an SQL query:
the output is generally like this in the php_error.log: