24
votes

Basically, I've seen people using @ before their function calls, not for every function, but for some kind of extension functions like file_get_contents(), mysql_connect() and so on.

And yes, the question is: For what purpose are there these @s before function calls?

Or in other words, what is the difference between @file_get_contents() and file_get_contents()?

5

5 Answers

41
votes

@ is an error control operator. Basically it's suppressing errors.

7
votes

It's the PHP's error control operator used to suppress any error generated by the function call.

1
votes

The @ symbol in front of a function prevents errors from being displayed when the function is called.

1
votes

@function doesn't show any error messages on its HTML output, while a regular function call will.

0
votes

I have similar doubt about @ used in front of functions. To avoid this I made some verification before the function call. My example is:

if ( is_file($filename) ) $timestamp = filemtime( $filename );