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.

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);

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.