0

Possible Duplicates:
Reference - What does this symbol mean in PHP?
Should I use @ in my PHP code?

For example, when deleting a file in PHP. @unlink($file); or unlink($file);

I've heard bad things about using @. Can someone explain why we should or shouldn't use this?

Community
  • 1
  • 1
KRB
  • 4,875
  • 17
  • 42
  • 54
  • Any error suppression without handling them can lead to bad things. – John Giotta Aug 16 '11 at 13:48
  • 2
    `@` suppresses any warnings/errors, so (IMHO) if you're just suppressing it you're not _properly_ dealing with it. – Brad Christie Aug 16 '11 at 13:48
  • Warnings are there for a reason. – Ed Heal Aug 16 '11 at 13:49
  • Also see the [Warning in the PHP Manual](http://docs.php.net/manual/en/language.operators.errorcontrol.php) – Gordon Aug 16 '11 at 13:50
  • Don't. But in production you can turn off error reporting all together. Regular uses have no need to see PHPs error messages. – Andre Backlund Aug 16 '11 at 13:51
  • @Andre turning off error reporting and not showing them to users is two different things and can be configured individually. You still will want to know when errors happen, especially in production. So you dont turn them off at all. You just log them instead of showing them. – Gordon Aug 16 '11 at 14:01

2 Answers2

2

If you use it on something that doesn't matter whether the operation was successful or not. If you needed to delete someone from a secure database, you probably wouldn't want to suppress a warning coming from that script.

But most of the time you'll want to hear the errors and warnings, so limited use of this in PHP is best, but there are the very few times it comes in handy.

nkcmr
  • 10,690
  • 25
  • 63
  • 84
1

The @ symbol suppresses any errors. If your script is failing to unlink()in your example above, you wouldn't see any error output about it. Its use is at your discretion for bug squashing or not. Though, personally I try to avoid its use because I want to know about any errors.

Blake
  • 2,294
  • 1
  • 16
  • 24