0

I would like to have all php notices yellow, warnings orange and fatal errors red. I'm thinking of a method that could be implemented in any class and, in case of error, would change outputs color. Maybe wrap around <span style="class:color">$error</span> or similar.

Any ideas/suggestions/pointers how to achieve that?

5
  • 4
    Implement a custom error handler, and emit the span styles based on the error type. Commented Jan 12, 2012 at 16:23
  • 2
    Since fatal errors cannot be handled by user code, that part of the scheme at the least is not achievable. But in any case, I don't see any practical benefit to doing this. Any kind of error is something that you should only see once (before you fix it). Commented Jan 12, 2012 at 16:23
  • @BoltClock that is an asnwer, not a comment… @ Jon I don't think it's about practicality – I think it's a nice gimmick. Otherwise you wouldn't output any errors at all and use the Apache error.log instead… Commented Jan 12, 2012 at 16:24
  • @feeela: I'd rather post something a little more comprehensive :) Commented Jan 12, 2012 at 16:26
  • I think you have already answered your own question, I can't see much wrong with what you suggest, you could perhaps redirect to a generic error page passing it some context of the error etc, but the possibilities here are in my opinion somewhat endless. p.s. it is usually best not to display over informative errors to the public i.e. just say 'ooops sorry' and redirect them back to the home page or back to where ever they were etc. Commented Jan 12, 2012 at 16:29

3 Answers 3

9

If you haven't already, try Xdebug first. Learn to love that Xdebug orange and save yourself a ton of grief implementing a custom color-coded error handler.

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

Comments

1

You can use set_error_handler() to register your own error handler and, based on the type of error that is triggered, add the coloring you would like.

Comments

0

Have a look at: set_error_handler()

$errno will contain one of the error-constants (E_ERROR, E_WARNING), that way you can decide on what to do.

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.