What does the @$ syntax mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steve_the_canuck
Forum Newbie
Posts: 8
Joined: Fri Jan 30, 2009 6:36 pm

What does the @$ syntax mean?

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: What does the @$ syntax mean?

Post by Benjamin »

If the array index is not defined, the error will be suppressed.
mubeena
Forum Newbie
Posts: 17
Joined: Fri Jan 30, 2009 4:26 am

Re: What does the @$ syntax mean?

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: What does the @$ syntax mean?

Post 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.
Post Reply