Monday, February 7, 2011

Reasons why PHP would echo errors, even with error_reporting(0)?

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) and ini_set('display_errors',0) with no luck.

  • 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 :)

  • Use log_errors for them to be logged instead of displayed

    Valdemarick : Still causes the same error, unfortunately. I'm looking for a way to do this without modifying php.ini. Is that possible?
  • 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.
    From Wimmer
  • 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

    From troelskn

0 comments:

Post a Comment