5

I'd be glad if someone could explain the architecture of PHP error handling to me. Some specific questions are:

  • At what stage does the default error handler read the relevant PHP configuration options?
  • Does a custom error handler ignore these options completely?
  • How can I make a custom error handler respect the configuration?

1 Answer 1

5

It's pretty much as you suspect. A custom error handler has to probe for all settings itself and react accordingly.

The set_error_handler example first checks the current active error level, and compares it to the first callback parameter (bitwise and) which denotes the current error type:

if (!(error_reporting() & $errno)) {

But to initially test if you actually are supposed to print errors, you would need also:

ini_get("display_errors") or return;

Or to react to more settings and emulate the default error handler, even ini_get("html_errors") etc. Unless you do all that manually, your user error handler would display all errors. They are not filtered, the callback receives everything.


The PHP default error handler is php_error_cb around line 850 here:
http://svn.php.net/viewvc/php/php-src/trunk/main/main.c?revision=309647&view=markup#855

It does a bit more, but also queries the ini registry. That's where error_reporting always saves the current state to.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That answers all my questions!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.