PHP为什么即使有error_reporting(0)也会回显错误的原因?
时间:2020-03-05 18:57:29 来源:igfitidea点击:
不管我们告诉它禁用什么,为什么php都会强制显示错误的原因有哪些?
我试过了
error_reporting(0); ini_set('display_errors',0);
没有运气。
解决方案
回答
请注意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 / ini_set是运行时评估,在"运行前"阶段执行的任何操作都不会看到它们的影响。
根据评论,错误是...
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /usr/home/REDACTED/public_html/dev.php on line 11
然后,将应用相同的一般概念。代码从不运行,因为它在语法上是无效的(我们忘记了";")。因此,永远不会遇到错误报告更改。
要解决此问题,需要更改系统级别的错误报告。例如,在Apache上,我们可以放置...
php_value error_reporting 0
在.htaccess文件中以禁止全部删除,但这取决于系统配置。
务实的是,不要写有语法错误的文件:)
回答
使用log_errors使它们被记录而不是显示
回答
为了防止显示错误,我们可以
- 输入.htaccess文件:php_flag display_errors 0
- 将代码拆分到单独的模块中,其中主要(父)php文件仅设置error_logging,然后将include()其他文件包含在内。
回答
如果该设置是使用php_admin_value在Apache中指定的,则无法在.htaccess或者运行时中进行更改。
请参阅:http://docs.php.net/configuration.changes