how to slience all PHP errrors and warnings in runtime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

how to slience all PHP errrors and warnings in runtime

Post 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
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Read the PHP Manual entry on error_reporting().
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

Thanks foobar, I will do that
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

FYI: if you have parse errors, they will not be silenced by having code to change error_reporting.
Post Reply