On your production site you should show a standard message when an error occurs.
In your dev site, feel free to spit out the error with stack trace etc. I have written an error handler which throws an exception on all errors, warnings, notices etc. This has proved very useful and looks something like this:
/*
* Error handling:
* Convert errors to exceptions.
* Make warnings fatal, make errors fatal. We don't want to continue.
*/
// error handler function
function ErrorToException($errno, $errstr, $errfile, $errline)
{
// Ensure that errors are suppressed properly.
$reporting_level = error_reporting();
if (($errno & $reporting_level) == 0) {
return;
}
// Otherwise, cause a fatal error and spit out relevant info.
$error_type_names =
array(E_USER_ERROR => "User Error",
E_USER_WARNING => "User Warning",
E_USER_NOTICE => "User Notice",
E_ERROR => "Error",
E_WARNING => "Warning",
E_NOTICE => "Notice");
if (isset($error_type_names[$errno])) {
$errname = $error_type_names[$errno];
} else {
$errname = "Unknown error $errno";
}
$exception_string = "Unexpected " . $errname . ":" . $errstr;
throw new Exception($exception_string);
}
set_error_handler ("ErrorToException");
Of course this assumes you're using PHP5. But any older version is decrepid and should not be used for new work.
Mark