The Joel on Software Discussion Group (CLOSED)A place to discuss Joel on Software. Now closed. |
||
|
This community works best when people use their real names. Please
register for a free account.
Other Groups: Joel on Software Business of Software Design of Software (CLOSED) .NET Questions (CLOSED) TechInterview.org CityDesk FogBugz Fog Creek Copilot The Old Forum Your hosts: Albert D. Kallal Li-Fan Chen Stephen Jones |
I've tried to look up what the @ operator does in PHP using the online help manual at
http://www.php.net/manual but failed. What does @ do in PHP? The line of code in question is: $mail_sent = @mail( $to, $subject, $message, $headers );
PHPNewbie Monday, February 25, 2008
The error control operator: http://us.php.net/manual/en/language.operators.errorcontrol.php
Generally you'll use that when you want to handle any errors yourself rather than having PHP output the error message to the client and possibly abort. One thing to watch out for, especially when porting code written for a newer PHP: If you call a nonexistent function with @, your script will abort with no error message.
clcr Monday, February 25, 2008
try..catch is wrong tool if you want to completely ignore an error. @ is so much simpler and more straight forward. It's a very rare thing to use but occasionally it makes sense.
@ doesn't "ignore" an error - it prevents an error message being written out to the web page you're producing.
The error still occurs, and must still be handled (or can still be ignored) in exactly the same way as without the @ prefix.
Nit Picker Monday, February 25, 2008
A valid use in my book is to replace this:
if ( IsSet ( $_GET['SomeVar'] ) && Trim ( $_GET['SomeVar'] ) != '' ) { ... } with this: if ( Trim ( @$_GET['SomeVar'] ) != '' ) { ... } in other words: use it when you absolutely know what you are doing and know the results (eg: don't throw @ in your code just because you don't know how to fix a error message :). |
|
Powered by FogBugz


