Ah, the error suppression operator (@)

It seems like such a fantastic idea, just put it in front of your function and no more error, right? 

Well, kind of… In order to understand the @ operator you need to understand a bit of how the php engine works, i.e. that @ doesn’t really “suppress” the error, instead it turns error_reporting to 0, performs the activity, and turns error_reporting back to what it was originally.

Seriously, that’s all it does, and it does it slowly (in other words, it works faster to make those error_reporting calls yourself).

Also remember that if you have a custom error_handler registered you have to check to see if @ was used by calling if(error_reporting() == 0) at the start of your handler…

Bottom line? It’s better to work around the error if at all possible, check to see if a file exists before working on it, and handle errors in your db code properly.

@ is NOT your friend 😉


Note: This post is a shamelessly copied version of the forum post originally by auroraeosrose, here: http://www.phpwomen.org/forum/index.php?t=rview&goto=1372&th=288#msg_1372

The reason I have copied it is because I have thought it useful and I don’t want to lose it should that forum be taken down at whatever point.

by Tom
July 17, 2007