Search code examples
phperror-reporting

Prevent calls to error_reporting() and/or ini_set('display_errors', 'On') from overriding php.ini settings


I had this setting in my php.ini file:

error_reporting = E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR

But I was still receiving thousands of NOTICE and WARNING entries in the error log every minute. I of course realize I would better deal with those errors, but this is not my code and I am not being paid to do that, I just needed to get rid of those fat error_log files (Gbs per day).

I searched through the code and removed all error_reporting() calls, and that did the trick but, is there a way to disallow error_reporting() from overriding php.ini settings?

Could I also prevent calls to ini_set('display_errors') from overriding php.ini settings?


Solution

  • is there a way to disallow error_reporting() from overriding php.ini settings?

    Maybe.

    If you're using mod_php under Apache (or FastCGI via FPM), you can use php_admin_value and php_admin_flag to force certain INI settings in such a way that ini_set will be unable to override.

    Unfortunately I don't know of a way to neuter error_reporting other than disable_functions -- but this will throw a PHP Warning every time it's used.

    (As a side note, I find it curious that a developer would set an error reporting level in production and still be producing such a high volume of logs.)