php - 是否可以跟踪当前的 PHP 函数/方法?
问题描述
我有一个 PHP 类方法,其中包含许多条件语句,如果某些条件为真,它会停止/返回。
对于调试,我想知道哪个条件实际上使函数返回控件。
public function handle_request() {
if ( ! $this->is_data_writable() ) {
return;
}
if ( ! $this->user_has_permissions() ) {
return;
}
if ( 'active' != $this->object->status ) {
return;
}
// do the stuff
}
我无法控制调用它的函数/方法。
解决方案
您可以对其使用日志处理
public function handle_request() {
if ( ! $this->is_data_writable() ) {
error_log("is_data_writable", 3, "/var/tmp/my-errors.log");
return;
}
if ( ! $this->user_has_permissions() ) {
error_log("user_has_permissions", 3, "/var/tmp/my-errors.log");
return;
}
if ( 'active' != $this->object->status ) {
error_log("not_active", 3, "/var/tmp/my-errors.log");
return;
}
// do the stuff
}
您可以使用自己的错误处理程序自定义错误处理,以便在发生错误或警告或您需要记录的任何内容时为您调用此函数。
推荐阅读
- javascript - 无法使用 javascript 在 animateCC 中循环图层
- asp.net-mvc - 列表的模型绑定
一个元素列表失败 - python - PySpark - 数据框操作
- c++ - 如果 std::variant 的析构函数包含 void* 数据,它会做什么
- mongodb - MongoDB / Mongoose如何通过_id返回嵌套子文档
- python - 列表中的递归问题
- python - Pandas 合并多列,NaN
- python - Python 调用 request() 到 SSL 站点不指向 netrc
- imagemagick - 错误 126 缩略图在 mediawiki 和 imagemagick 上不起作用
- haskell - 生成此 SOP 函数时,如何修复类型错误,包括“无法对 Traversable 进行量化”?