Custom PHP error handler not respecting error suppression

When using a custom error handler in PHP, it is going to track all errors, warnings and notices regardless of what you specified with error_reporting();.

When using @ to suppress errors or warnings, they still go to the custom error handler.

To respect error/warning/notice suppression whilst in your custom PHP error handler you need to check for error_reporting which is changed during the function call.

error_reporting() settings will have no effect and your error handler will be called regardless – however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

That means, the following will ignore errors you suppressed using @:

You can also suppress E_STRICT in general for example:

Leave a Reply

Your email address will not be published. Required fields are marked *