1

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?

2
  • 3
    I would say that "bugs and errors" mainly come from reinventing the wheel... Commented Dec 10, 2011 at 20:01
  • Remember, you're using PHP, so you can make a nicely formatted HTML+CSS error log :) Commented Dec 10, 2011 at 20:08

2 Answers 2

2

Look, you are just mixing the matters.

There are actually two persons you have to notify

  1. A programmer
  2. A user.

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_errors and log_errors settings 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.

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

Comments

1

Leaking php errors can be quite dangerous security-wise, because it can reveal the innards of your application and server. It is generally good practice to switch display_errors Off for production and use a custom error handler instead. For development, it does not really matter.

I will cite the php doc on display_errors:

This is a feature to support your development and should never be used on production systems (e.g. systems connected to the internet).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.