What are the reasons why PHP would echo errors, even with error_reporting(0)?

 ̄綄美尐妖づ 提交于 2019-11-29 17:57:20

问题


What are some reasons why PHP would force errors to show, no matter what you tell it to disable?

I have tried

error_reporting(0);
ini_set('display_errors', 0); 

with no luck.


回答1:


Note the caveat in the manual at 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).

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.


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

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...

php_value error_reporting 0

in a .htaccess file to suppress them all, but this is system configuration dependent.

Pragmatically, don't write files with syntax errors :)




回答2:


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.



回答3:


Use phpinfo to find the loaded php.ini and edit it to hide errors. It overrides what you put in your script.




回答4:


Is set_error_handler() used anywhere in your script? This overrides error_reporting(0).




回答5:


Use log_errors for them to be logged instead of displayed




回答6:


If the setting is specified in Apache using php_admin_value it can't be changed in .htaccess or in runtime. See: http://docs.php.net/configuration.changes




回答7:


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



回答8:


Just add the below code in your index.php file:

ini_set('display_errors', False);


来源:https://stackoverflow.com/questions/78296/what-are-the-reasons-why-php-would-echo-errors-even-with-error-reporting0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!