@ character before a function call

Php

Php Problem Overview


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

init_get($somevariable);

@init_get($somevariable);

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

It silences errors and warnings. See Error Control Operators.

Solution 3 - Php

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

Solution 4 - Php

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.

Solution 5 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnixieView Question on Stackoverflow
Solution 1 - PhpsolidgumbyView Answer on Stackoverflow
Solution 2 - PhpSampsonView Answer on Stackoverflow
Solution 3 - PhpAntonioCSView Answer on Stackoverflow
Solution 4 - PhpGeorgeView Answer on Stackoverflow
Solution 5 - PhpDaniel SorichettiView Answer on Stackoverflow