Thread: About $_post

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Smile About $_post


    Hi everyone,

    I have to change the php code which someone wrote before.
    There is one thing I dont understand.
    There are so many @$_post in her/his codes which I've never seen before.

    Could anyone tell me the difference between,
    @$_post and $_post ?

    Thank you,

    tomomou
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    this "@" is the poor man's version of error handling. It simply suppresses any error from the following expression.

    The "@" is bad practice, escpecially when used excessively. So you can thank your predecessor for leaving you sh*tty code and start repairing it (unless it doesn't matter, anyway).
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You're probably seeing it in something like the following:
    PHP Code:
    $var = @$_POST['var']; 
    The appropriate way to do that is:
    PHP Code:
    $var = isset($_POST['var']) ? $_POST['var'] : ''
    If you did it the first way without the @, then an E_NOTICE would be thrown if a value named 'var' were not submitted with the POST request. However, handling that error by suppressing it is bad practice as already mentioned.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo