Page 1 of 1

What does the @$ syntax mean?

Posted: Fri Jan 30, 2009 6:41 pm
by steve_the_canuck
Hi,

I'm new to PHP and using symfony for a project. I noticed the following line:

in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))

I can see what the line is doing, but I'm not sure what the @ symbol does in the syntax. I've done some searches through the PHP reference manuals and I can't seem to find any documentation about this syntax.

Can anyone explain what it does?

Thanks,
Steve

Re: What does the @$ syntax mean?

Posted: Fri Jan 30, 2009 6:49 pm
by Benjamin
If the array index is not defined, the error will be suppressed.

Re: What does the @$ syntax mean?

Posted: Sat Jan 31, 2009 2:08 am
by mubeena
See this example,

Code: Select all

 
$checking_updateQuery =  mssql_query($updateQuery);
    $outResult = @mssql_fetch_array($checking_updateQuery);
To avoid the warning message, we are using this '@' symbol here.

Re: What does the @$ syntax mean?

Posted: Sat Jan 31, 2009 2:25 am
by requinix
If this thread is going to stay alive then I might as well make this comment:

Don't rely on this thing to fix your problems. If you get a warning message you should try to fix the code first. I know of no circumstances where a @ is necessary, and precious few where I consider it excusable. An E_NOTICE is a minor issue, an E_WARNING something you should pay attention to, and an E_ERROR as a major bug. Address as many of these as you can and there will be less bugs, and everybody can agree that fewer bugs in the code is a good thing.

If you want to hide errors on a global scale, edit your php.ini file and change display_errors to "off" or zero. This isn't a good idea for a testing environment but a must for production. Errors should then be logged somewhere (see the error_log setting) so you don't miss out on the messages.