Jump to content

"@" before calling a function


squiblo

Recommended Posts

What is the reason for this?

 

A Lazy programmer. The @ suppresses the reporting of php detected errors. Using it would mean that the programmer did not bother to check if the function he put it on would generate an error, so he simply suppressed the error reporting.

 

There's no reason at all to put @ in any code. On a live server display_errors should be OFF so that any errors that php detects won't be displayed any way and there's no point in there being any @'s in the code. On a development system display_errors should be ON so that you get immediate feedback of any problems so that you can fix them, not hide them.

 

Also, someone has posted that the @ actually causes extra php code to be executed simply because it is present. It doesn't say, if there is an error, don't report it, it apparently reads and saves the existing error_reporting level, temporarily sets error_reporting to zero, then restores error_reporting after the statement has completed. Php.net has made a statement about wanting to speed up the @ handling in future versions of php, which tends to confirm that simply putting it in code, even if there is no error, is causing this extra code to be executed.

 

The @ also suppresses the logging of errors (log_errors is ON) so in a real application, it would suppress any information about problems occurring in your code, such as a legitimate visitor supplying some valid but unexpected data or a hacker deliberately trying to break into your script and triggering errors. You would want to know if either of these things are occurring so that you could fix them. Using @ would hide this type of information.

 

We also get occasional posts in the forum where someone has an @ in their code and the code is not outputting the errors. So, using @ can slow down the development and debugging cycle by hiding problems in your code when you most need to see them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.