33

Possible Duplicate:
What is the use of the @ symbol in PHP?
Reference — What does this symbol mean in PHP?

what does using <?php echo @$fnameerror; ?> mean. why use @ before variable in php

Cœur
  • 37,241
  • 25
  • 195
  • 267
shaz
  • 367
  • 1
  • 4
  • 7
  • 1
    See [What is the use of @ symbol in php? ](http://stackoverflow.com/questions/1032161/what-is-the-use-of-symbol-in-php). – Matthew Flaschen Nov 11 '10 at 04:54
  • @Matthew I get the feeling shaz knows what it does in general, just not why it would be used to prefix a variable. – Phil Nov 12 '10 at 02:05

5 Answers5

26

error control operator .. suppresses error messages ..

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
9

@ is pure evil. It's not a good idea to use. You can find an explanation about it here.

It can cause massive debugging headaches because it will even suppress critical errors.

GWW
  • 43,129
  • 11
  • 115
  • 108
  • 2
    Actually wrong. If you define a custom error handler, you can still receive all messages despite the @ suppression operator. Therefore it's in fact preferable to e.g. isset() decoration. – mario Nov 11 '10 at 05:23
  • 1
    Maybe so, but I've seen way more people use it without a custom error handler and have way too many headaches dealing with it. – GWW Nov 11 '10 at 05:25
7

It's used to avoid the error notice.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
JuLy
  • 483
  • 2
  • 5
  • 12
6

The only reason I can think of to use the error suppression operator before a variable would be to suppress E_NOTICE errors if the variable is undefined.

As others have mentioned, this is a bad idea. It's much better to actually deal with errors than ignore them.

Phil
  • 157,677
  • 23
  • 242
  • 245
4

If you want to avoid notices and warnings use @ sign before variable

Conex
  • 832
  • 8
  • 17