3

Possible Duplicate:
ini_set() scope of effect?

I'm working on a site and for development I like to see my errors in the browser, so I have the following code at the top of my site:

error_reporting(E_ALL);
ini_set("display_errors", 1);

According to the php docs, ini_set "Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending." When I read that I was kind of worried. It seems like ini_set() changes the setting globally and then restores it at the end of the script.

My question, does that means that any other php files that are running at the same time, on the same server will also display errors in the browser?

Community
  • 1
  • 1
crunkchitis
  • 718
  • 2
  • 10
  • 19
  • No, it does not mean that. Globally is only for the currently active script, on the global level of it. For all functions etc. – hakre Oct 29 '12 at 23:11
  • all the files included after the above 2 lines will return error. not any other files which is irrelevant to this page. – Deepak Oct 29 '12 at 23:11
  • 2
    It changes just the state in the current PHP runtime/process. It does not *set* the *ini file*. It should better be called `set_ini_runtime_value()`. Also note that enabling `display_errors` is too late in index.php, if that already contains a fatal syntax error e.g. The current script must successfully run first before the setting could be modified. – mario Oct 29 '12 at 23:11
  • 1
    Just a tip: you need `error_reporting(E_ALL|E_STRICT)` to catch *all* errors. Go figure :) – chelmertz Oct 29 '12 at 23:15
  • @chelmertz: Not in PHP 5.4 — that was fixed –  Oct 29 '12 at 23:40
  • @qwzjk: who's running 5.4? :) – chelmertz Oct 30 '12 at 08:36
  • Also set start up errors ini_set("display_startup_errors", 1); – nerkn May 08 '14 at 12:00

1 Answers1

1

No. The name may be misleading a bit, but it only affects your current script (that one tha called ini_set()). If you want to make this global adjust php.ini (or use .htaccess)

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141