Jump to content

What's the "@" operator?


mynameisrich

Recommended Posts

Ok, posting here is a last resort. (Apparantly you can't search for the string "@" with Google or php.net's search box. It matches everything.)

What does the '@' operator mean? I've seen it in scripts and can't figure it out. The online documentation at php.net lists '@' as an operator in the order of precedence, with a link to the Types pages, but none of the Types pages has any mention of it. Niether do any of the other language syntax reference pages. (I know. I looked through them all!)

I've played around with it on the php command line, and as far as I can tell, it doesn't actually do anything.

Sample code I saw with it:

[code]if (!$result = @ mysql_query ($query, $connection))
     showerror();
[/code]
Any help?

Thanks!
Link to comment
Share on other sites

The @ sign suppresses errors. If there is an error with something the script will continue to run.

you should never really use the @ operator because you will never get errors outputed on the screen and you will be sitting there wondering why you have nothing showing on your page.

Some people use them just so the clients do not see errors and page names on public sites. I guess this is fine, but while developing your web site you should not be using the @ sign.

Ray
Link to comment
Share on other sites

No! The @ sysbol supresses the errors. Meaning no error is shown and allows the script to continue running as though there is no error.

take this script for example:
[code]<?php

if($_GET['var'])
{
    echo $_GET['var'];
}

?>
<a href="?var=hello">Say hello</a>[/code]
When you run that script for the first time, you'll get the following notice error:
[code]Notice: Undefined index: var in C:\server\www\test.php on line 3[/code]If you placed an @ just before $_GET the error message will not be shown. ie:
[code]if(@$_GET['var']))[/code]
This is error suppression. It doesn't affect what a variable contains it just stops an error message being displayed.
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]you should never really use the @ operator[/quote]

I would never say you should not use it, and more of say you should use it in as most places as possible.

Say a connection to a database, you will definitly want to use it there and use your own error output messages on runtime enviroments..

Debugging/development.. yeah you should not use it, but on a release of a script what if the connection to db failed and say username is shown in the error string, thats not information id really want to be showing.

If theres a possible chance an error may arise on an action, I would recommend supressing it and handle the error with your own output.
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.