Jump to content

Archived

This topic is now archived and is closed to further replies.

AV1611

@mail()

Recommended Posts

Can someone tell me what the @ does when you put it in front of a function?

i.e.

mail()
vs.
@mail()


Thanks...

Share this post


Link to post
Share on other sites
Error suppression. If the function errors out, it won't display anything to the user.

The best way to use that is to set the function output equal to something and if it's not what you expect, you can append the error to a log file or email yourself and the user will never know the difference. You can also use it to display a "nice" error message to the user instead of the script spitting out what line the error came from and what the name of your file was, etc, etc.

Share this post


Link to post
Share on other sites
thanks... maybe if I remove it from my script, it'll tell me why it quit working LOL

Share this post


Link to post
Share on other sites
That's very true!

Share this post


Link to post
Share on other sites
[!--quoteo(post=359267:date=Mar 28 2006, 02:56 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 02:56 PM) [snapback]359267[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Error suppression. If the function errors out, it won't display anything to the user.

The best way to use that is to set the function output equal to something and if it's not what you expect, you can append the error to a log file or email yourself and the user will never know the difference. You can also use it to display a "nice" error message to the user instead of the script spitting out what line the error came from and what the name of your file was, etc, etc.
[/quote]

Just out of interest how would you make a custom error page come up if there is an error in the function?

Share this post


Link to post
Share on other sites
As long as the processing is all done before any output, you would redirect the user with the header() function.

Share this post


Link to post
Share on other sites
[!--quoteo(post=359282:date=Mar 28 2006, 03:09 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 03:09 PM) [snapback]359282[/snapback][/div][div class=\'quotemain\'][!--quotec--]
As long as the processing is all done before any output, you would redirect the user with the header() function.
[/quote]

what i eamnt was on a MYSQL you can do like

or die(mysql_error)

or in place of that redirect it to another page and encode the error in the URL

how would you do it on a function

would you still do or die(php_error) lol
i am not too sure

Share this post


Link to post
Share on other sites
No... you cannot run an "or die()" on a regular function. You just have to know what the output is supposed to be and if it isn't in that "range", you have to deal with it accordingly. Like I said, if you're processing before any output is created, you can redirect to another page and show some sort of error. If the processing or the running of the function is AFTER some output has been created, you'll just have to create your error message right there.

Share this post


Link to post
Share on other sites
There are ways to add error handling on your functions, but if you can help it don't use '@'. Don't hide your errors, fix them. In my years of PHP experience I have never had to use '@' to cover an error. I was always able to find a way to make everything work without suppressing errors. That's not to say that there are never situations where you might need the '@', just that they are not all that common. If every other line of your code is full of '@'s then you need to rethink your code a bit.

Share this post


Link to post
Share on other sites
txmedic,
I could not agree more...

the code already had the @, I just didn't know what it was, I've never used it, and have written quite a bit of code to this point...

Share this post


Link to post
Share on other sites

×

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.