0

Pls what is the best approach considering (performance, security etc.) to implement an error function. Something in the line of ..

function trap_errors($error_code, $parametrs...)
{
$error_code = array => ('1001 = Error description1', '1002 = Error description2',..etc.
)
}

I dont know if the above makes sense. Any pointers?..

asked Dec 26, 2010 at 8:39
2
  • 1
    I see no sense in such a function at all. What is your goal? What you're trying to achieve? Commented Dec 26, 2010 at 9:18
  • Until you give more details as "Col. Shrapnel" requests, let me plug an Open Source project I'm working on that collects errors, sends them to a central reporting app, filters them, emails staff and creates tickets. The ticket system is at elastik.sourceforge.net and you want to look at the ErrorReportingService module (look in the general documentation). Commented Dec 26, 2010 at 9:40

1 Answer 1

1

You can define an (global) error handler:

function myErrorHandler($type, $msg)
{
 echo $type . ' ' . $msg;
}
set_error_handler("myErrorHandler");

And trigger an error by your own which arrives the upper defined function:

trigger_error("This is an error!", E_USER_ERROR);

Look here to see the list of error types.

This catches each error in PHP: your ones or the system errors, e.g.

answered Dec 26, 2010 at 9:06
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but is it possible to convert the error type to an understandable info? Instead of 256 say "System could not process your input.."
You can use a converter function where convert the constants to a string by using a switch block.
@Frank you don't need such conversion at all. You have completely misunderstood error handling. You don't have to explain every system error to the user. There are only 2 options - 503 and 404. thats ALL

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.