I’m developing a very simple but (hopefully) solid framework that just fits my needs. No more things then the really needed one.
I know that someone of you might find me the last “re inventor of the wheel”, but I believe in this project and I think that other framework are complex for no reason some times; and we all know that bugs and errors grow exponentially as the framework complexity.
I came to the problem of handling errors: PHP errors, framework errors (PHP errors group) etc.
There are a lot of ways to do that but I usually prefer the simple one.
Should I manage all the PHP errors that can occur during the initialization of the framework with Exceptions or set_error_handler() or should I build a simple error handler that show (if we are in developer mode) or log (if we are not in developer mode) the errors?
For example:
include('file.php'); // required files for the application
should I check for it and return “nice looking” error messages such as “The framework cannot run because a file is missing”. Or should I let PHP error trigger its own error?
How would you manage this type or errors?
Look, you are just mixing the matters.
There are actually two persons you have to notify
Understanding that, you will see that there is no problem what to choose: both.
For the programmer, the default PHP handler is enough. Driven with
display_errorsandlog_errorssettings PHP will do exactly what you want:show (if we are in developer mode) or log (if we are not in developer mode) the errors.For the user (and a search engine) a “nice looking” 503 error page is obligatory.
Of course, without whatever details like “file is missing”. Just an apology page.
The only question is how to trigger that.
A good reason to make use of a custom error handler.