Jump to content

Recommended Posts

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.

  "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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.