Search code examples
phperror-handlingerror-reportingerror-logini-set

How to mute error logging of a disabled function despite an at operator @?


Does anybody know how to make a disabled function (in my case ini_set()) stop throwing an error? I usually have it like @ini_set() but on this WP plugin, it STILL fills the error_log with:

[30-Apr-2018 12:01:39 UTC] All-in-One Event Calendar: ini_set() has been disabled for security reasons @ /home/burp/public_html/wp-content/plugins/all-in-one-event-calendar/all-in-one-event-calendar.php:81 #2

I suspect it's because that ini_set actually sets a callback function and another ini_set() is called within that ini_set() function defined. Here's the error_log'ed line 81 in question:

@ini_set( 'unserialize_callback_func', 'spl_autoload_call' );

I'm the server administrator and I disabled ini_set() years ago and I have no problem with this, I just want to MUTE the error logging on that script. +100 WP sites that all include ini_set() are NOT reporting any error, only this particular one, despite the @ before the ini_set().


Solution

  • The error control operator @ would normally suppress the error message, however a custom error handler defined with set_error_handler can still cause the error to be logged via error_log.

    error_reporting will return 0 if the call that triggered the error was preceded by an @. The error handling function should check that before logging the error:

    if (error_reporting()) {
        // Report the error
        error_log(...)
    }
    

    Looking at the calendar code below, you can see that error_log is called for non-fatal errors. You could simply add a check for error_reporting in that script.

    https://github.com/wp-plugins/all-in-one-event-calendar/blob/86c4e20dab7b199b20207fb3918a8807f7342fab/lib/exception/handler.php#L287

    Alternatively you could disable error_log or re-enable ini_set for that page.

    POST MORTEM EDIT: It is worth noting that despite the error log specifying the error was caused by ini_set() being disabled, the error was originating from deeper in the callback of the function defined within the ini_set() in question (the line 81 displayed in OP). So basically, the error is not even relevant at all. It's bubbling up to the ini_set() and creates confusion as the reason and even the line is not about the error that was actually thrown.