【问题标题】:php error log for class files in different directory不同目录中类文件的php错误日志
【发布时间】:2021-10-21 21:58:43
【问题描述】:

请原谅一个关于记录 php 脚本错误的高级问题,至少最初是这样。 php error_log 将在与主 php 脚本不同目录的类文件中记录错误是否有效?

我有两个 php 文件

pages/add_edit_xxxx.php

class/class_xxxx.php

add_edit_xxxx.php 依赖于类文件中的公共函数

如果我故意在 pages/add_edit_xxxx.php 中引入错误,那么 pages/error_log 会正确记录错误的行号

如果我故意在 class/class_xxxx.php 中引入错误,那么 class/error_log 有时会记录错误,有时保持不变

我无权访问 php.ini 但我猜设置是可以的,因为有时 class/error_log 会记录错误,但通常不会记录错误。

我在设置文件中有这个:

ini_set("include_path", '/home/xxxx/php:' . ini_get("include_path") );  
error_reporting(E_ERROR);
@session_start();

在页面开头调用/add_edit_xxxx.php

include_once("settings.php");

我希望这足以让人们思考是否应该可靠地捕获和记录类文件中的错误是否是一个有效的期望。目前我无法重新创建创建日志时的场景 - 但这是昨天编写的 class/error_log 条目的示例

[20-Oct-2021 19:00:48 UTC] PHP Parse error:  syntax error, unexpected '$tempRS' (T_VARIABLE) in /home/xxxxx/public_html/xxxxx.com/class/class_xxxx.php on line 36

如果我删除了故意插入的错误(例如缺少分号),则页面运行良好。

谢谢

【问题讨论】:

  • 在向服务器发送值之前使用 if 语句进行验证,这样您就不会遇到意外的$tempRS 错误。
  • 谢谢@dlk,但我想捕捉错误的原因是帮助调试有时冗长的脚本

标签: php error-handling


【解决方案1】:

通过更新设置文件中的这一行来解决:

error_reporting(E_ERROR); 

error_reporting(E_ALL); 

【讨论】:

    猜你喜欢
    • 2011-10-03
    • 2020-04-22
    • 1970-01-01
    • 2015-08-03
    • 2023-03-31
    • 2012-05-10
    • 2013-01-22
    • 1970-01-01
    • 2018-04-26
    相关资源
    最近更新 更多