Jump to content


Photo

@mail()


  • Please log in to reply
11 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 28 March 2006 - 01:50 PM

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

i.e.

mail()
vs.
@mail()


Thanks...

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 March 2006 - 01:56 PM

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.

Info: PHP Manual


#3 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 01:57 PM

i THOUGHT @ supressed error message

#4 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 28 March 2006 - 01:58 PM

thanks... maybe if I remove it from my script, it'll tell me why it quit working LOL

#5 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 March 2006 - 01:59 PM

That's very true!

Info: PHP Manual


#6 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 02:07 PM

[!--quoteo(post=359267:date=Mar 28 2006, 02:56 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 02:56 PM) View Post[/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?

#7 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 March 2006 - 02:09 PM

As long as the processing is all done before any output, you would redirect the user with the header() function.

Info: PHP Manual


#8 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 02:14 PM

[!--quoteo(post=359282:date=Mar 28 2006, 03:09 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 03:09 PM) View Post[/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

#9 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 March 2006 - 02:26 PM

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.

Info: PHP Manual


#10 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 03:14 PM

Oh i see, Ok fair enough ty very much

#11 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 29 March 2006 - 07:48 AM

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#12 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 29 March 2006 - 12:45 PM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users