Is it possible (and if so, how) to turn on php error reporting to the screen for just one page? I currently have all error reporting to the screen switched off in php ini.
Or another way of asking - if I use error_reporting(E_ALL) on a single page, will it also display errors on other pages (what I don't want)?
Thanks!
Using
error_reporting(E_ALL)
will enable error reporting for only that page!To display errors use,
ini_set("display_errors", 1)
If you call
error_reporting()
within a PHP script, it will only affect that script's runtime (i.e. anything it executes after that call, including other scripts which have been included). It won't modify server configuration etc.However, it's worth noting that if the script encounters an error before it can make that call, it won't have any effect (i.e. error reporting behaviour will be unchanged). That can be a particular problem if you have a syntax error or similar.
EDIT: It occurs to me that you may want to leave error reporting enabled in your configuration, but only enable
display_errors
as needed. That way you can still get errors written to a log file, but they'll only appear on-screen when you want.Call
error_reporting(0)
at the beginning of a script to do this. It will block all runtime errors. However, it isn't recommended to do this, except possibly in production code.Read more about error_reporting() here