PHP 抛出“未定义变量”通知

发布于 2024-10-08 12:33:12 字数 116 浏览 0 评论 0原文

我想记录除未定义的变量条目之外的所有错误...不应该这样做吗?

    error_reporting(E_ERROR | E_WARNING | E_PARSE);

I want to log all errors except for undefined variable entries... shouldn't this do it?

    error_reporting(E_ERROR | E_WARNING | E_PARSE);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终难愈 2024-10-15 12:33:12

它将隐藏所有通知,但这应该可以做到:

error_reporting(E_ALL ^ E_NOTICE);

不过,你应该解决问题。

It will hide all notices, but this should do it:

error_reporting(E_ALL ^ E_NOTICE);

You should fix the problems instead though.

梦里寻她 2024-10-15 12:33:12

这些通知是通过您的自定义错误处理程序记录的。这是你必须适应的事情。查找 set_error_handler() 及其定义的函数。它有这样的声明:

function user_err_log ($errno, $errstr, $file, $line, $context) {

并且您想要检查 $errno 以将通知与错误分开:

    if ($errno == E_NOTICE or $errno == E_USER_NOTICE) {
         // log to a debug file instead
         return;
    }

error_reporting(0x0000) 和错误抑制运算符 @< 的优点/code> 与使用 isset 进行语法抑制相比,重要通知仍然会到达您的自定义错误处理程序。但如果你不关心它们,你就必须手动将它们整理出来。对于记录错误,您完全不应该这样做。 (我个人会设计一种方法将通知发送到其他地方,以防万一。)

These notices are getting logged through your custom error handler. This is the thing you have to adapt. Look for set_error_handler() and the function it defines. It has a declaration like:

function user_err_log ($errno, $errstr, $file, $line, $context) {

And you want to check $errno to separate notices from errors:

    if ($errno == E_NOTICE or $errno == E_USER_NOTICE) {
         // log to a debug file instead
         return;
    }

The advantage of error_reporting(0x0000) and the error suppression operator @ over syntactic supression with isset is that vital notices still reach your custom error handler. But you have to manually sort them out, if you don't care about them. Which for logging errors, you rightly shouldn't. (I would personally devise a method to spool notices elsewhere, just in case.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文