mynameisrich Posted April 10, 2006 Share Posted April 10, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/ Share on other sites More sharing options...
trq Posted April 10, 2006 Share Posted April 10, 2006 It is the error supresor. Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/#findComment-25534 Share on other sites More sharing options...
craygo Posted April 10, 2006 Share Posted April 10, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/#findComment-25535 Share on other sites More sharing options...
mynameisrich Posted April 10, 2006 Author Share Posted April 10, 2006 Thanks!So in the example I gave, if an error were generated by mysql_query, what would happen? Would $result be set to the error that was raised? (Which would then evaluate to false and cause the "showerror()" function to be called?) Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/#findComment-25544 Share on other sites More sharing options...
wildteen88 Posted April 10, 2006 Share Posted April 10, 2006 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]<?phpif($_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. Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/#findComment-25557 Share on other sites More sharing options...
DrDre Posted April 10, 2006 Share Posted April 10, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/7032-whats-the-operator/#findComment-25574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.