0

I wrote a custom error handler for my site and I'm aware that PHP doesn't allow handling of parse and fatal errors. Is there something I can do to make it handle these errors? I don't want them being outputted to the user (but I want to use my error handler for them).

Thanks!

iamandrus
  • 1,400
  • 2
  • 16
  • 25
  • possible duplicate of [Handle fatal errors in PHP using register_shutdown_function()](http://stackoverflow.com/questions/4410632/handle-fatal-errors-in-php-using-register-shutdown-function) – netcoder Jun 19 '11 at 08:11

2 Answers2

1

You could try register_shutdown_function. If there is an error (even parse one) in one of files you have included/required this function will still be called.

Though you won't be able to use debug_backtrace because shutdown function will be called outside of your error, you could try to use error_get_last to get some information about the error.

Buksy
  • 11,571
  • 9
  • 62
  • 69
1

If it can't parse your script, it won't be able to parse your custom error handler.

You should have display_errors off in your php.ini and also set error_reporting to none when your site is in production.

Also, I believe set_error_handler() can handle fatal errors.

alex
  • 479,566
  • 201
  • 878
  • 984
  • ^ What he said, there are good reasons that your script fails on parse errors, it simply does not know what to do – Connor Smith Jun 19 '11 at 06:04
  • Was afraid of that. Oh well. And no, I already had set_error_handler() on it and it didn't work. – iamandrus Jun 19 '11 at 06:20
  • As at PHP 7.4.10, `set_error_handler()` does not still handle fatal errors; just set `display_error` to off, this works. – Ebuka Jan 09 '21 at 12:06