Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a custom PHP error handler respect PHP configuration?

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?
like image 232
markus Avatar asked Apr 18 '11 07:04

markus


1 Answers

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.

like image 154
mario Avatar answered Sep 23 '22 15:09

mario