squiblo Posted August 2, 2010 Share Posted August 2, 2010 In some codes I have seen, I have noticed an "@" before a function is called, e.g... @flush(); What is the reason for this? Quote Link to comment Share on other sites More sharing options...
awjudd Posted August 2, 2010 Share Posted August 2, 2010 It is suppressing any errors which may occur / be thrown while in the function. http://php.net/manual/en/language.operators.errorcontrol.php ~juddster Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 2, 2010 Share Posted August 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.