161

What is the difference between these two function calls in PHP?

init_get($somevariable);

@init_get($somevariable);
NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
nixie
  • 1,621
  • 2
  • 10
  • 4

5 Answers5

248

the "@" will silence any php errors your function could raise.

Mike Eng
  • 1,593
  • 4
  • 34
  • 53
solidgumby
  • 2,594
  • 1
  • 16
  • 9
  • But what if you put `@` in front of PHP's `trigger_error` function? I have seen that in some code, but its behavior is inconsistent for me so far. In some cases, I do see the error being reported by the configured error handler and in other cases it does seem to get reported. – fritzmg Mar 06 '16 at 10:40
  • 4
    The `@` will temporarily set `error_reporting` to 0 but will not "suppress" the error. – solidgumby Mar 08 '16 at 12:26
50

It silences errors and warnings. See Error Control Operators.

Sampson
  • 265,109
  • 74
  • 539
  • 565
40

As already answered the @ will stop the error (if any) from showing up.
In terms of performance this is not recommended.

What php is doing is:

  • reading the error display state
  • setting the error display to show no errors
  • running your function
  • setting the error display to it's previous state

If you don't want any errors showing up use error_reporting(0);.

Or just write bug free code :P

AntonioCS
  • 8,335
  • 18
  • 63
  • 92
  • Prefer to put zero, but if that works, great didn't know about it :) – AntonioCS Jan 05 '10 at 08:54
  • 3
    What about functions that you do not control, like mail for example? Which other options exist? I am using @ right now, but would be great to be able to do in different way – spuas Feb 04 '13 at 15:12
8

http://www.faqts.com/knowledge_base/view.phtml/aid/18068/fid/38

All PHP expressions can be called with the "@" prefix, which turns off error reporting for that particular expression.

George
  • 81
  • 1
6

As everyone said, it stops the output of errors for that particular function. However, this decreases performance greatly since it has to change the error display setting twice. I would recommend NOT ignoring warnings or errors and fixing the code instead.

Daniel Sorichetti
  • 1,921
  • 1
  • 20
  • 34
  • Thanks to all for your answers. That code is not mine, I was only looking at the phpBB code for curiosity, so I have no problems of performance. :) Thanks again. – nixie Jan 05 '10 at 13:06