Home > PHP > Why @ is NOT your friend

Why @ is NOT your friend

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 loose it should that forum be taken down at whatever point.

Related posts on coderchris.com:

  1. Dodgy Wordpress Plugins and Themes
    Recently I have been doing a LOT of research into various wordpress themes and plugins...
  2. Installing Flash Media Server 2 On Linux (CentOS 4.4)
    Recently I was asked by a client to look at purchasing and installing FMS2 on...
  3. Bloody MySQL Bugs
    I’m looking to setup some replication between two servers and server B has none of...
  4. ctype_digit rtfm!
    For the last 5-10 minutes I've been wondering why a check on a variable which...
  5. Advanced Syntax-Hilighting Online Code Editors – A Wordpress IDE?
    When I write plugins for wordpress I like to do it on a test blog...

Categories: PHP Tags:
  1. No comments yet.
  1. No trackbacks yet.