为什么不在 PHP 中使用最高的错误报告级别?

发布于 2024-07-24 21:32:28 字数 890 浏览 2 评论 0原文

我想让你给出为什么有人不应该在 PHP 中使用尽可能高的错误报告级别的原因?

设置最高级别的方法:

PHP < 5.4:

error_reporting(E_ALL | E_STRICT);

PHP >= 5.4:

error_reporting(E_ALL);

PHP 所有版本(按照 配置文件):

error_reporting(2147483647);

PHP所有版本(我的配置,-1将包含所有错误并且易于记住)

error_reporting(-1);

我的经验:< /strong>

I want you to give reasons why someone should not use the highest possible error reporting level in PHP?

Ways to set highest level:

PHP < 5.4:

error_reporting(E_ALL | E_STRICT);

PHP >= 5.4:

error_reporting(E_ALL);

PHP all versions (as recommended for config files):

error_reporting(2147483647);

PHP all versions (my config, -1 will contain all errors and is easy to remember)

error_reporting(-1);

My experiences:

  • there is no reason for low reporting levels
  • never used the error control operator
  • use to convert all errors to exceptions via set_error_handler and customized exception class to overwrite file and line

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

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

发布评论

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

评论(4

零崎曲识 2024-07-31 21:32:29

从系统管理员的角度来看……有时您对旧代码或新代码无能为力。 有些开发人员没有正确调试,如果你在无关紧要的事情上浪费任何人的时间,经理会觉得你很滑稽(不确定这是否会让任何人感到不安,但如果前后结果相同,那么这并不重要)。 我很高兴我可以禁用这些通知并专注于任何实际问题。

另外,这只是一个盲目的尝试,但也许有一些方法可以通过使用 error_log() 调用在调试方面做一些有点奇特的事情。

Well from a sys admin PoV...sometimes there is nothing you can do about the code- legacy or new. Some developers don't debug properly and a manager is going to look at you funny if you waste anyone's time with something that doesn't really matter (not sure if this will upset anyone, but if the result is the same before and after, then it doesn't really matter). I for one am very happy I can disable the notices and focus in on any real problems.

Also, this is just a shot in the dark, but maybe there is some way to do something a little fancy with this in terms of debugging by using error_log() calls.

伤痕我心 2024-07-31 21:32:28

我个人更喜欢在错误报告的最高级别进行编码,并修复我的代码生成的所有警告。 但是,我可以设想您可能希望在较低级别工作的几个原因:

  1. 您可能正在使用会发出大量警告的遗留代码。 如果代码正常工作,这不是问题,但“噪音”可能会分散您的注意力并阻止您看到真正的问题。 在这种情况下,可能需要降低错误报告级别。
  2. 在生产环境中,您可能只想记录错误。 这有两个好处,这意味着您的错误日志仅包含需要注意的关键问题,并且它将节省磁盘空间(并减少磁盘 I/O)。

撇开题外话不谈:在生产环境中,您应该运行“display_errors = Off”和“error_logging = On”以防止用户看到 PHP 错误(其中可能包含敏感信息,例如数据库连接属性),并在错误发生时收集错误日志。 因此,您的生产错误报告级别和相关设置可能与您希望在开发中运行的级别不同。

I personally prefer to code at the highest level of error reporting, and fix all warnings generated by my code. However, I can envisage a couple of reasons why you might want to work at a lower level:

  1. You may be working with legacy code which emits a lot of warnings. If the code works correctly this is not an issue, but the "noise" may be distracting and prevent you from seeing the real problems. In this situation it may be desirable to lower the error reporting level.
  2. In a production environment you may want to log only errors. This has two benefits, it means your error logs contain only critical issues which need attention, and it will save disk space (and reduce disk i/o).

Off topic aside: In production environment you should run "display_errors = Off" and "error_logging = On" to prevent users from seeing PHP errors (which may contain sensitive information e.g. database connection properties), and collect a log of errors as they occur. So your production error_reporting level and related setting may be different to what you'd prefer to run in development.

↘紸啶 2024-07-31 21:32:28

我认为没有充分的理由,除了吉姆在他的第一点中所说的,运行不能或不会更改的遗留代码。

您肯定应该在开发过程中以最高级别运行它,并清除所有警告和通知,除非您有充分的理由不这样做。

如果您有充分的理由不在开发过程中修复通知,则应该将其记录下来并使用错误控制运算符以避免日志混乱。

I think there is no good reason, except maybe what Jim says in his first point, running legacy code that cannot or won't be changed.

You should most certainly run it at the highest level during development and wipe out every warning and notice unless you have a great reason not to.

If you have a great reason not to fix a notice during development, you should document it and use the error contorl operator to avoid cluttering the logs.

兲鉂ぱ嘚淚 2024-07-31 21:32:28

除了吉姆的观点之外,我总是建议使用最高级别的错误报告进行编码,因为它应该为您提供更好的可移植性和(无疑)更好的性能。

Besides Jim's points I would always suggest coding with the highest level of error reporting as it should offer you better portability and (questionably) better performance.

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