tags:

views:

65

answers:

3

I want to keep errors out of my PHP output stream. I only want output of things I explicitly echo.

Looking at my php.ini, is "display_errors" the only configuration I need to change?

+2  A: 

Instead of modifying php.ini, you can call this at a very early part of your code:

error_reporting(0);

Note that this means fatal errors will die silently as well, so it makes it a little difficult to debug at first.

BoltClock
+1, but I think it's prettier to use the `E_NONE` constant instead of the int.
karim79
@karim79: I feel dumb now - I *knew* there was a constant for that! Yet for some reason it's not documented in [the PHP manual](http://www.php.net/manual/en/errorfunc.constants.php) at all...
BoltClock
@BoltClock - You're right! How strange is that!
karim79
@karim79: anyway, thanks for the heads-up! Running a recursive file search in all my PHP script folders for `error_reporting(0)` now... ;)
BoltClock
While the sentiment is decent, I'm not sure this is a good way to go. That means that you'll have no idea even if an error happened. I'd say it's probably better to just let PHP log all errors rather than turning off error reporting all together. At least that gives you a place to see if all of a sudden your site breaks (due to whatever)...
ircmaxell
@karim79: hmmm, `E_NONE` does not appear to be defined in my PHP 5.3. I tried `constant('E_NONE')` and it says constant not found. Rolling back my answer just in case...
BoltClock
I don't want to do it on a page by page basis because i have adevelopment and production environments. I want to tune each once.
John Leonard
A: 

You can modify that INI directive and change the flag to 0 (False) or disable error_reporting on a page by page basis

error_reporting(0)

Typically Production environments should be on display_errors = 0 Though not all of us have both Development and Production environments

You can also change the "verbosity" of the error messages by passing different values to error_reporting function (Or by changing the INI value for it in php.ini) More information on that can be found here: PHP: Runetime Configuration - error_reporting

Marco Ceppi
+1  A: 

I only recommend that if we're talking about a production machine. display_errors will hide them from the user, but make sure you have log_errors and error_log set in the php.ini so you'll see them on your regular log analysis (you do, right?).

For a development machine, I recommend keeping display_errors on and error_reporting(E_ALL | E_STRICT) so you'll see if anything is fishy.

Maerlyn
My development environment is reporting everything down to warnings and that's great.I just want to make sure my production environment stays silent for the user while error logging for me behind the curtain.
John Leonard
@John my toughts exactly.
Maerlyn