ahs10 Posted December 21, 2007 Share Posted December 21, 2007 i have created a function that is called in replace of die, usually after a mysql_query() attempt, but sometimes in an else statement. i don't however use this function to replace die() when it's used because of denied user permissions. anyweezer, this function is just error reporting that's easier on the eye, emailing me the __FILE__, __LINE__, and mysql_error, and opening up a form in a new window that allows the user to associate their name, email address, and any notes to the error report that was just emailed to me. so with that setup, the form is opened in a new window, so the original error causing page is underneath it and still open. what i just realized to is that the script wasn't killed either. now i could add die() to my function, but do i need too? are there instances where continuing to run a script after an mysql_error is bad? is there a reason why "$result = mysql_query($query) or die(mysql_error())" is one of the most common lines in php? like i said, i don't use this function to replace die() when it's denying a user access, there's usually a mysql_error to go along with it, and if not it's in a bizarre else statement that will probably never get executed. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/ Share on other sites More sharing options...
Lumio Posted December 21, 2007 Share Posted December 21, 2007 Read this: http://www.php.net/set_error_handler That may help you. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420800 Share on other sites More sharing options...
ahs10 Posted December 21, 2007 Author Share Posted December 21, 2007 thanks for this information, it helps me ask a better question on this page, someone posts..... "error_fatal(E_ALL^E_NOTICE); // will die on any error except E_NOTICE" why do you want to do that? why is running the script after E_NOTICE occurs alright? why is running the script after any other bad? Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420812 Share on other sites More sharing options...
Lumio Posted December 21, 2007 Share Posted December 21, 2007 The ^ sign tells to ignore the following state. But I can't really help you with that Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420842 Share on other sites More sharing options...
GingerRobot Posted December 21, 2007 Share Posted December 21, 2007 People often work with error reporting set to ignore notices. You get notices for undefined variables/constants amongst other things. Because they occur with this sort of problem, often the script can continue to run - though it may not always run as expected. For example, this: <?php $array = array('key' =>'some value'); echo $array[key]; ?> Would produce an undefined constant notice. However, PHP can continue to execute the script, because it assumes you meant to enclose the word key in quotes. Setting error reporting to include notices is a good way of finding bugs though. If you made a typo with a variable name somewhere, it'll help you find it. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420845 Share on other sites More sharing options...
ahs10 Posted December 21, 2007 Author Share Posted December 21, 2007 thank yall for your help, but i don't think i'm explaining myself well here at all. i know what the ^ symbol does, i know that custom error reporting is a common practice, i know that the script can continue to run after there was an error. i'd like to know the danger in it running after an error. let's say for example that you.... $query = "SELECT * table"; $result = mysql_query($query); // this query fails, giving an error $var = mysql_result($result, 0); // since the query failed, i'm sure this would kick an error too, irrelevant to my point though that $var doesn't have a value $query2 = "UPDATE different_table SET whatever = ' " . $var . " ' "; $result2 = mysql_query($query2); // this query doesn't fail ...so with this remedial example, i've updated one table with an incorrect value because i didn't die at my first error. i'm looking for more examples like this, why it would be bad not to die after an error. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420860 Share on other sites More sharing options...
GingerRobot Posted December 21, 2007 Share Posted December 21, 2007 As you've pretty much pointed out, it depends entirely on the script. Bad things could occur if you let a script continue to run when there should be some form of error. Consider the pseudocode: if(person doesn't have any enough money){ //show error } //complete purchase Without exiting the script, the purchase is still complete, even though the error is shown. As i said though, wether or not you would run into any problems depends entirely on the script. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420868 Share on other sites More sharing options...
PHP_PhREEEk Posted December 21, 2007 Share Posted December 21, 2007 The 'danger' involved in allowing the script to continue depends on the actual problem, so there isn't a clear cut answer to your question. This is also a "programmer's call" situation. Some coders like to pay attention to even the smallest of details, and others just feel that if the script 'works', that's good enough. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420874 Share on other sites More sharing options...
ahs10 Posted December 21, 2007 Author Share Posted December 21, 2007 thanks. Quote Link to comment https://forums.phpfreaks.com/topic/82738-solved-benefits-of-die/#findComment-420890 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.