即使使用 error_reporting(0),PHP 也会回显错误的原因是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/78296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the reasons why PHP would echo errors, even with error_reporting(0)?
提问by Valdemarick
What are some reasons why PHP would force errors to show, no matter what you tell it to disable?
无论您告诉它禁用什么,PHP 都会强制显示错误的一些原因是什么?
I have tried
我试过了
error_reporting(0);
ini_set('display_errors', 0);
with no luck.
没有运气。
回答by Adam Wright
Note the caveat in the manual at http://uk.php.net/error_reporting:
请注意http://uk.php.net/error_reporting手册中的警告:
Most of E_STRICT errors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to include E_STRICT errors (and vice versa).
大多数 E_STRICT 错误是在编译时评估的,因此在 error_reporting 增强以包含 E_STRICT 错误的文件中不会报告此类错误(反之亦然)。
If your underlying system is configured to report E_STRICT errors, these may be output before your code is even considered. Don't forget, error_reporting/ini_set are runtime evaluations, and anything performed in a "before-run" phase will not see their effects.
如果您的底层系统被配置为报告 E_STRICT 错误,这些可能在您的代码被考虑之前就被输出。不要忘记,error_reporting/ini_set 是运行时评估,在“运行前”阶段执行的任何操作都不会看到它们的影响。
Based on your comment that your error is...
根据您的评论,您的错误是...
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/REDACTED/public_html/dev.php on line 11
解析错误:语法错误,意外的 T_VARIABLE,需要 ',' 或 ';' 在第 11 行的 /usr/home/REDACTED/public_html/dev.php
Then the same general concept applies. Your code is never run, as it is syntactically invalid (you forgot a ';'). Therefore, your change of error reporting is never encountered.
然后应用相同的一般概念。您的代码永远不会运行,因为它在语法上无效(您忘记了“;”)。因此,永远不会遇到您更改错误报告的情况。
Fixing this requires a change of the system level error reporting. For example, on Apache you may be able to place...
解决此问题需要更改系统级错误报告。例如,在 Apache 上,您可以将...
php_value error_reporting 0
php_value error_reporting 0
in a .htaccess file to suppress them all, but this is system configuration dependent.
在 .htaccess 文件中将它们全部取消,但这取决于系统配置。
Pragmatically, don't write files with syntax errors :)
务实地,不要写有语法错误的文件:)
回答by Willem
To prevent errors from displaying you can
为了防止显示错误,您可以
- Write in a .htaccess: php_flag display_errors 0
- Split your code in separate modules where the main (parent) PHP file only sets the error_logging and then include() the other files.
- 写入 .htaccess: php_flag display_errors 0
- 在单独的模块中拆分您的代码,其中主(父)PHP 文件仅设置 error_logging,然后 include() 其他文件。
回答by khalid
回答by colmde
Is set_error_handler()used anywhere in your script? This overrides error_reporting(0).
是否set_error_handler()在脚本中的任何地方使用?这将覆盖error_reporting(0).
回答by ob-ivan
Pragmatically, don't write files with syntax errors :)
务实地,不要写有语法错误的文件:)
To ensure there's no syntax errors in your file, run the following:
为确保您的文件中没有语法错误,请运行以下命令:
php -l YOUR_FILE_HERE.php
This will output something like this:
这将输出如下内容:
PHP Parse error: syntax error, unexpected '}' in Connection.class.php on line 31
回答by dheerendra
Just add the below code in your index.phpfile:
只需在index.php文件中添加以下代码:
ini_set('display_errors', False);
回答by troelskn
If the setting is specified in Apache using php_admin_value, it can't be changed in .htaccess or at runtime.
如果使用php_admin_value在 Apache 中指定设置,则无法在 .htaccess 或运行时更改。
See: How to change configuration settings
请参阅:如何更改配置设置
回答by Vinko Vrsalovic
Use log_errorsfor them to be logged instead of displayed.
使用log_errors来记录而不是显示它们。

