31

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
  • 34,719
  • 24
  • 185
  • 251
shaz
  • 347
  • 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
  • 37,365
  • 14
  • 77
  • 84
8

@ 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
  • 41,431
  • 11
  • 106
  • 104
  • 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
  • 70,503
  • 15
  • 107
  • 148
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
  • 141,914
  • 21
  • 225
  • 223
4

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

Conex
  • 831
  • 8
  • 17