0

why also getting default error handler message with custom one which i setted with set_error_handler here is my code below

     function custom_handler($error_level,$error_message){
 echo   "[$error_level] $error_message";
}

set_error_handler("custom_handler",E_WARNING);
require_once('try.php')

and here is the output

"[2] require_once(try.php): failed to open stream: No such file or directory Fatal error: require_once(): Failed opening required 'try.php' (include_path='D:\software\xampp\php\PEAR') in D:\software\xampp\htdocs\samples\code.php on line 14"

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
zeeeuu
  • 19
  • 4
  • If I remember correctly (and not out of date) set_error_handler doesn't deal with fatal errors. – Jonnix Jan 09 '19 at 11:26
  • Possible duplicate of [set\_error\_handler() doens't work for FATAL error](https://stackoverflow.com/questions/8527894/set-error-handler-doenst-work-for-fatal-error) – Jonnix Jan 09 '19 at 11:27

1 Answers1

1

As per php manual:

require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.

and

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

Your custom handler is showing the E_WARNING, the default handler is showing the E_COMPILE_ERROR.

DigiLive
  • 1,093
  • 1
  • 11
  • 28