Jump to content

What does @ in front of variable mean?


ollie007

Recommended Posts

Not turn off exactly (though you're not wrong).

 

It supresses errors. If you're not fully comfortable with it, I wouldn't recommend it at this stage.

 

I use it to supress the mail() function when working locally, as I don't have a mailing facility through my set up. Apart from that I prefer catching all errors, as you should.

Link to comment
Share on other sites

Not turn off exactly (though you're not wrong).

 

Actually, it's quite accurate saying it turns them off. The way it works internally is that it sets error_reporting=0, executes the statement and then reverts error_reporting to whatever it was before. This is what makes it so inefficient.

 

This:

@someFunction();

is equivalent to

$oldErrorReporting = error_reporting(0);
someFunction();
error_reporting($oldErrorReporting);

Link to comment
Share on other sites

More often than not, it really shouldn't be used. There are a couple functions out there that output errors when they aren't executed, at which point it can be a good thing, but most people who use it are just being sloppy in their programming.

Link to comment
Share on other sites

On a live server, display_errors will be OFF (and if they are not, you should globally make them off), so there is no reason at all to use @ in any code. On a development system, where display_errors would be ON, you want to see all errors, even if to just confirm that your code is executing down an expected path when something like a mail server is not available.

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.