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"

2
  • If I remember correctly (and not out of date) set_error_handler doesn't deal with fatal errors. Commented Jan 9, 2019 at 11:26
  • Possible duplicate of set_error_handler() doens't work for FATAL error Commented Jan 9, 2019 at 11:27

1 Answer 1

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.

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

Comments

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.