为什么不在 PHP 中使用最高的错误报告级别?
我想让你给出为什么有人不应该在 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>
- 低报告级别没有理由
- 从未使用错误控制运算符
- 用于通过 set_error_handler 和自定义异常类来覆盖文件和行
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从系统管理员的角度来看……有时您对旧代码或新代码无能为力。 有些开发人员没有正确调试,如果你在无关紧要的事情上浪费任何人的时间,经理会觉得你很滑稽(不确定这是否会让任何人感到不安,但如果前后结果相同,那么这并不重要)。 我很高兴我可以禁用这些通知并专注于任何实际问题。
另外,这只是一个盲目的尝试,但也许有一些方法可以通过使用 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.
我个人更喜欢在错误报告的最高级别进行编码,并修复我的代码生成的所有警告。 但是,我可以设想您可能希望在较低级别工作的几个原因:
撇开题外话不谈:在生产环境中,您应该运行“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:
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.
我认为没有充分的理由,除了吉姆在他的第一点中所说的,运行不能或不会更改的遗留代码。
您肯定应该在开发过程中以最高级别运行它,并清除所有警告和通知,除非您有充分的理由不这样做。
如果您有充分的理由不在开发过程中修复通知,则应该将其记录下来并使用错误控制运算符以避免日志混乱。
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.
除了吉姆的观点之外,我总是建议使用最高级别的错误报告进行编码,因为它应该为您提供更好的可移植性和(无疑)更好的性能。
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.