cyberRobot Posted May 11, 2011 Share Posted May 11, 2011 I know that the following lines of code can be used to prevent errors from being displayed: <?php error_reporting(0); ini_set('display_errors', 0); ?> Is there a reason to use one over the other? Is it better to use both? Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/ Share on other sites More sharing options...
fugix Posted May 11, 2011 Share Posted May 11, 2011 I know that the following lines of code can be used to prevent errors from being displayed: <?php error_reporting(0); ini_set('display_errors', 0); ?> Is there a reason to use one over the other? Is it better to use both? honestly, that is a good question, one that i would like the answer to as well. It seems to me that both results would be the same, just two different ways of executing it. error_reporting(0) sets the level that you specify for the runtime of the script. While ini_set('displlay_errors', 0) will set the configuration option until the script is finished executing. Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/#findComment-1213950 Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 They are the same. Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/#findComment-1213959 Share on other sites More sharing options...
mikosiko Posted May 11, 2011 Share Posted May 11, 2011 "WHAT" (error_reporting) and "WHERE/WHEN" (display_errors) are not the same... but obviously if "WHAT" is "nothing"... "WHERE/WHEN" doesn't make sense and looks like the same further reading http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/#findComment-1213968 Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 Ahh, for some reason I read it as ini_set('error_reporting', #) Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/#findComment-1213971 Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2011 Share Posted May 11, 2011 error_reporting determines what errors are reported (kind of why they named it that.) display_errors determines if the errors that are reported will be output to the browser. You should always have error_reporting set to at least E_ALL or even better a -1. You want all errors to be reported and code should not normally produce any errors during its execution. You should only get errors for abnormal things that your code did not take into account. On a development system, display_errors should be ON (you want to see the errors so that you can find an fix what is causing them.) On a live server display_errors should be OFF and log_errors should be ON (you don't want to display any php detected errors but you do want to log them so that you have a record of any problems so that you can find an fix them.) Even if you have error_reporting set to zero, php must still detect and handle each error as it occurs. The reporting and display/logging of the error is just the last step in the error handling code. Quote Link to comment https://forums.phpfreaks.com/topic/236125-preventing-errors-from-being-displayed-which-function-is-better/#findComment-1213972 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.