PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I would think the act of suppressing errors would be a bad habit. Personally I like to know when my proggie doesn't do what it should! I guess it's more for the end user?
techleet wrote:I would think the act of suppressing errors would be a bad habit. Personally I like to know when my proggie doesn't do what it should! I guess it's more for the end user?
Generally, yes, its a bad habit. There are rare exceptions to the rule.
d11wtq wrote:It only surpresses non-fatal errors. Syntactical and fatal errors will still be shown.
I think this is an important point relating to the code posted in the question. A call to a query gives an error when a connection has not been established or the DB server is unavailable. Both of those can usually be caught by with checks before the query.
techleet wrote:I would think the act of suppressing errors would be a bad habit. Personally I like to know when my proggie doesn't do what it should! I guess it's more for the end user?
Generally, yes, its a bad habit. There are rare exceptions to the rule.
it's a bad habit only if you don't have your own error handling functions built in...
$_errors = array();
$sql = "SELECT * FROM mytable";
$rst = @mysql_query($sql);
if(!$rst) {
throwError(mysql_errno(), 'The query has failed. Report was : : ' . mysql_error());
}
function throwError($id=false, $message="") {
global $_errors;
if ($id === false) {
$id = mysql_errno();
}
if (empty($message)) {
$message = mysql_error();
}
if ($id !== 0) {
array_push($_errors, array('id'=>$id, 'message'=>$message));
}
}
if(!empty($_errors)) {
echo 'There was an error in the sql! Error dump reports :';
print_r($_errors);
}
of course this code is untested... but you get the point..
lots of people either don't like php's error reporting, or they would like to impliment their own. suppressing php's error reporting is a good idea and definately not a bad habbit if you have your own error control. otherwise, yeah, it's kinda dumb and is a bad habit because you then have no way of knowing what went wrong.
For anyone who's tempted to go nuts with error surpressing: If you're using PHP5 I strongly suggest you take a look into Exception handling (try/catch).