SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is the use of @

    im reading some php samples and i wondering what is the use of @ sign in this code.. can som1 explain this.. tnx

    $doencrypt=false;
    if (@$_REQUEST["do"]=="encrypt")
    $doencrypt=true;

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It suppresses the warning message if there is no element with index 'do' in the $_REQUEST array.
    Birnam wood is come to Dunsinane

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is also slower than isset().

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't rely on it too heavily, it can have the effect of hiding logic errors from you when debugging code.
    Except where things might fail for technical reasons (e.g copying from remote server) it's best not to supress error messages or warning arbitrarily.

  6. #6
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used to work with a guy who liked to do just that, use the @ operator to suppress error messages coming from functions. The worst part was that he used it on the topmost function of his framework, which had the side effect of supressing errors in all subsequent functions called by this one (ie: all the other function calls), therefore making the entire application impossible to debug, since the page would just fail silently without any visible errors.

    Be *very* careful with the @ operator and its side effects.
    Garcia

  7. #7
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    suppress error messages coming from functions
    It is not being used in that context here. It is being used to suppress a notice from a variable that is not set. Normally people use isset to suppress the notice. @ involves less code but takes longer to run. Apart from that the end result is the same. As for displaying errors it's very amateurish and should be avoided in a working environment.

  8. #8
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    It is not being used in that context here. It is being used to suppress a notice from a variable that is not set.
    That's irrelevant. The OP wanted to know what was the use of the @ operator, so I think it's important to warn of the dangers of overusing it, specially to someone who just came into contact with it for the first time. My experience reflects precisely those dangers: several hours were spent debugging a simple error as a result of misusing the @ operator when it should have taken minutes.

    Quote Originally Posted by bokehman
    Normally people use isset to suppress the notice.
    isset() does not supress any notices or errors. It simply returns a boolean value.

    Quote Originally Posted by bokehman
    As for displaying errors it's very amateurish and should be avoided in a working environment.
    In that case, I would really like to know what your debugging process is. Without being able to see the errors that your application produces as you develop it, how do you locate bugs in your code?

    Ironically enough, while I was posting this, the forum database went down. I know this because the sitepoint developers took the trouble to display an error message explaining exactly what the problem was when this happened. Do you consider those developers amateurs for doing this?

    Saludos,
    Garcia

  9. #9
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    isset() does not supress any notices or errors. It simply returns a boolean value.
    In this context its only purpose though is to suppress a notice. Whether that is done with a boolean or other piece of code is irrelevant.
    Quote Originally Posted by ghurtado
    I know this because the sitepoint developers took the trouble to display an error message explaining exactly what the problem was when this happened. Do you consider those developers amateurs for doing this?

    Saludos,
    It was not a PHP error message though. It was a proper error message for user display. The @ operator was being used to suppress the PHP message in this instance.

  10. #10
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that case, I would really like to know what your debugging process is. Without being able to see the errors that your application produces as you develop it, how do you locate bugs in your code?
    You configure your development machine to display errors, and your production server (i.e the one your users use) to NOT display PHP errors, but to instead log them to file. When something fails (e.g DB being down) the users see the error message that you've prepared, and not the PHP error that discloses potentially sensitive information.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •