2

I`m writing a light PHP framework for learning purposes and I came up to a problem. In famous frameworks like Laravel for example, all errors are caught and displayed in a custom mode. I know that I can setup custom errorHandler and exceptionHandler for my application like this:

set_error_handler([$handler, 'errorHandler']);
set_exception_handler([$handler, 'exceptionHandler']);

I can even setup shut_down function in order to catch the fatal errors and in combination with error_get_last() I can throw them as exceptions.

register_shutdown_function([$handler, 'shutDownFunction']);

Then problem is that I cannot catch parse errors. It seems none of my handlers are catching a parse error. Is there a way to do that? Please help.

shAkur
  • 944
  • 2
  • 21
  • 45
  • You should be able to catch parse errors using the shutdown function, have a look at this answer to a similar question: https://stackoverflow.com/questions/1900208/php-custom-error-handler-handling-parse-fatal-errors – Matthew Brown Aug 10 '17 at 14:31
  • I did that as I mentioned in the original post but if I register it and right after I force the script to stop by writing something random like: "suifgisdfyigsdfyi" it won't catch my error. What am I doing wrong? – shAkur Aug 11 '17 at 07:06
  • Does this answer your question? [PHP : Custom error handler - handling parse & fatal errors](https://stackoverflow.com/questions/1900208/php-custom-error-handler-handling-parse-fatal-errors) – Nick Dec 19 '19 at 23:45

1 Answers1

0

In php 7 parser errors handled with set_error_handler callback.

El'
  • 401
  • 7
  • 19