Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The @ at the start of functions

Status
Not open for further replies.

altendew

Programmer
Mar 29, 2005
154
US
I see many functions that will be called like

Code:
$money = @foo('10');

Can anyone describe what this means?
 
'@' is PHP's error-supression operator. It is described in the PHP online manual here.


As a general rule, use of the "@" operator is not a good idea. It can supress errors you really need to see, and some programmers use it instead of code to handle errors gracefully.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks, but I dont understand why I have to use

Code:
@mysql_fetch_array($query);

Because I get an error when I use

Code:
mysql_fetch_array($query);

What is the difference!
 
Based on sleipnir's answer, that should be obvious. You don't get an error if you use error-supression operator, because it supresses the error. If there is none, error appears. If you show us the error we might help you explain what you're doing wrong and you could avoid the error in the first place (not just supress it).
 
Ok I hear all this talk about supressing, what does that mean, sorry to sound like a newb.
 
I posted a link to a page in the PHP online manual. If you have not done so already, I strongly recommend reading the page at that link. I can't explain it better than the manual does.



As to what "to supress" means, sorry, but I was mispelling the word. I should have spelled it "suppress", and the definition can be found here. Every meaning but meaning 4 could be applied here, and with the way some programmers use the "@"-operator, meaning 4 is appropriate, too.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Every function can either return a positive result (if everything works) or an error (if something unexpected happened). Errors (in non-user defined functions) usually arise because of too few, too many or incorrect (type) parameters. You can use the error-suppression operator (@) to hide these errors and ignore them. Simply, if this function gives you the error, do not show it and ignore it. Using this operator does have a good point. You can use it to write your own error-handling mechanism. In this case you will hide the default errors php gives you and handle the errors in your own script. However, if this is not what you're trying to do, supressing (hiding) errors is not smart, because your code produces some errors and does not work like you meant it to work, but you don't know what is wrong, because you hid the errors.

For your case, you should remove the @ operator and run the code. Paste the error in here along with the code and we will be able to tell you what's wrong with it, and you can then fix it so that it works and you don't need to use error supression.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top