Page 1 of 1

how to slience all PHP errrors and warnings in runtime

Posted: Wed Nov 02, 2005 5:53 am
by jasongr
Hi

I would like to silence all PHP warnings, error, notices and so on in my applicaiton
so that these will not be displayed to the user

I know that this can be configured in php.ini
can I configure this in runtime by calling PHP functions in my code?
if so, do I need to call these functions on every request the user performs in my site?

regards

Posted: Wed Nov 02, 2005 6:02 am
by foobar
Read the PHP Manual entry on error_reporting().

Posted: Wed Nov 02, 2005 6:05 am
by jasongr
Thanks foobar, I will do that

Posted: Wed Nov 02, 2005 6:07 am
by Jenk

Code: Select all

error_reporting(0);
ini_set('display_errors', 0);
Though I prefer to log all errors:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', '/path/to/log.txt');
And it's even better to ensure there won't be any errors by ensuring your code is robust :)

Posted: Wed Nov 02, 2005 7:29 am
by feyd
FYI: if you have parse errors, they will not be silenced by having code to change error_reporting.