5

I"m looking at someone code and it has many

@$_GET[];
@$_POST[];

What does the @ do?

j08691
  • 204,283
  • 31
  • 260
  • 272
Ahmad Khan
  • 529
  • 1
  • 7
  • 24

1 Answers1

13

@ in PHP suppresses any errors, and allows anything executed thereafter to silently fail (instead of output an error string (assuming show_errors=true)).

See the docs on error control operators for more information.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • 1
    This is a necessary hack if you need to send a HTTP header response later on in the code. – Teddy Sep 04 '13 at 20:05
  • 1
    I wouldn't argue necessary. However, if you're writing something that could potentially fail (and you've accounted for it if/when it does) but don't necessarily want PHP doing its own thing, you can use this prefix. (I see it commonly used for file access where you already test if a handle is good, and don't need PHP giving you problems about chmod or other errors) – Brad Christie Sep 04 '13 at 20:07
  • @Teddy: Your comment is extremely wrong. If you get the "headers already sent" warning it means that it is IMPOSSIBLE for you to send further headers. Suppressing the warning won't help since you still cannot send a header after the headers have been completed (as soon as you send non-header output, e.g. using `echo`, the headers are terminated with an empty line - and there cannot be any headers after that). – ThiefMaster Sep 05 '13 at 01:54
  • @ThiefMaster relax, I am just trying to provide a possible explanation as to why this code would have so many `@` lines in it. This was a comment, not an answer. – Teddy Sep 06 '13 at 13:23
  • I just wanted to make it clear so people don't believe suppressing errors make things work that cannot work – ThiefMaster Sep 06 '13 at 14:16