Hi,
I came across a way of sending emails which suppresses php errors if the mail server isn't set up:
$mail_sent = @mail($to,$subject,$msg,$headers);
- and I just wanted to confirm that you could do this with echo. On the login page of this site I'm working on, if the user enters the wrong details then the value of the username input is set to what the user entered (using the $_SESSION array). I have tried using:
<input type="text" name="username" value="<?php @echo $_SESSION['username']; ?>" />
but that caused a parse error, but it seems to work fine using 'echo @$_SESSION['username']'. Is this right? And does it work on all platforms/php versions? Also.. if I understand it correctly, could you use this to avoid errors with any undefined variable? I.e. echo @$_COOKIE['eatme'].@$_GET['you'] ..?
Thanks in advance!
Using @ as error suppressor?
Moderator: General Moderators
-
ben.artiss
- Forum Contributor
- Posts: 116
- Joined: Fri Jan 23, 2009 3:04 pm
-
mickeyunderscore
- Forum Contributor
- Posts: 129
- Joined: Sat Jan 31, 2009 9:00 am
- Location: UK
Re: Using @ as error suppressor?
@ suppresses errors from functions (I think), echo isn't a function.
But you shouldn't really be using @ so freely, it's better to error check rather than suppress.
But you shouldn't really be using @ so freely, it's better to error check rather than suppress.
-
ben.artiss
- Forum Contributor
- Posts: 116
- Joined: Fri Jan 23, 2009 3:04 pm
Re: Using @ as error suppressor?
Great stuff thanks for the advice - it looks like I haven't been taking the 'long route'!
One last thing though, just because it seems to work, does the @ work on both functions and variables? I only ask because it works as I want it to when I use 'echo @$_SESSION['username']'.
Re: Using @ as error suppressor?
According to PHP manual, the @ operator can be used before any expression (not only functions).
http://php.net/manual/en/language.opera ... ontrol.php
I also found a site with some interesting examples:
http://thesmithfam.org/blog/2006/05/07/ ... -operator/
Regards,
http://php.net/manual/en/language.opera ... ontrol.php
I also found a site with some interesting examples:
http://thesmithfam.org/blog/2006/05/07/ ... -operator/
Regards,