views:

78

answers:

4

This has been probably asked a lot of times, but couldn't find anything like this from searching, possible that I used wrong keywords - have no idea what is this called.

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

And yes, the question is, what for there are these @ before function calls?
Or in other words, what is the difference between @file_get_contents() and file_get_contents()?

Thanks in advance!

+8  A: 

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

fabrik
Thanks a bunch! +1, accepted (because of low-reputation and super-simple explanation)
Tom
You're welcome! :)
fabrik
@Tom I hope you do understand from this explanation that this symbol should be never used.
Col. Shrapnel
@Col. Shrapnel +1
fabrik
@Col. Shrapnel Ofcourse! I'm always interested in every error, so there is at least something to fix.
Tom
A: 

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

Chetan
http://php.net/manual/en/book.errorfunc.php
Ted
+3  A: 

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

codaddict
A: 

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

SkypeMeSM
Wondering why it's downvoted.
fabrik
what is? I don't understand.
SkypeMeSM
@fabrik the same reason as yours. But while yours is ambiguous (just "output"), this one is cleanly states HTML output, which, of course, is a nonsense. Error control has nothing to do with program's output.
Col. Shrapnel
@fabrik: Honestly I do not understand if you are mocking or genuinely asking. Either way I do not care. @Col. Shrapnel: Requesting you to type out your definition of error control for all of us to gain more insight on the subject. I agree that my answer lacks any depth, since I just said what I understood it to be :) Thanks.
SkypeMeSM
he was talking not to you. But to person who downvoted. Got it now? Error control consists of 2 parts: standard error output *destination* and *level* of error. Both `@` operator and `error_reporting` setting are control *level* of error. (@ sets it to 0) While `log_errors` and `display_errors` settings responsible for the destination. Latter one is responsible for what you have said: HTML output. While @ has nothing to do with it, id should be never used for that purpose
Col. Shrapnel
gotcha. thanks :) +1 to the Col. :)
SkypeMeSM