23

Is error_reporting(0) same as ini_set('display_errors', 0)? If not, what is the difference?

I'm also interested in security side of this code? Can I achieve 'so malicious users can't probe' with this?

2
  • 1
    The only difference is this: "Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.". Commented May 2, 2014 at 20:44
  • 1
    @AmalMurali - that's true of both functions. PHP files are parsed completely before any code in that file is executed, so any function you use to enable error reporting will not be executed if there are parse errors in the same file. Commented May 2, 2014 at 20:49

1 Answer 1

40

They are NOT the same, but in your use may have the same outcome.

  1. error_reporting is the level of reporting, NONE through ALL. This determines what types of errors are reported (E_NOTICE, E_WARNING, E_ALL, etc..).

  2. display_errors is whether to display those errors (output to browser, CLI, etc...) that are reported from 1.

If you set error_reporting(E_ALL) and ini_set('display_errors', '0') you can still get all errors reported in the log file but not displayed.

With error_reporting(0) you don't get any errors displayed or in the log and it doesn't matter the values of display_errors.

display_errors should be off in your production applications, preferably in php.ini so that information such as file paths, database names and usernames are not shown. Error reporting sent to the log is beneficial and should not be a security concern.

Sign up to request clarification or add additional context in comments.

2 Comments

Can I acchive this security task with them?
You want display_errors off in your app or preferably php.ini. Error reporting sent to the log is beneficial and should not be a security concern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.