What does various symbol means in PHP

This topic contains 4 replies, has 1 voice, and was last updated by  admin November 9, 2016 at 7:14 am.

  • Creator
    Topic
  • #4744

    admin
    Keymaster

    I was wondering what @ means in PHP language. I have seen people using $connect = @mysql_query(‘sql query here’); Not sure why. Could someone explain it for me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #4750
    Helpful
    Up
    0
    Down
    Not Helpful

    admin
    Keymaster

    The @ operator tells PHP to suppress error messages, so that they will not be shown.

    For instance, using:

    $result = mysql_query(“this is an invalid query”);
    would result in a warning being shown, telling you that the MySQL query is invalid, while

    $result = @mysql_query(“this is still an invalid query”);
    would not.

    Note, however, that this is very bad programming practice as it does not make error disappear, it just hides them, and it makes debugging a heck of a lot worse since you can’t see what’s actually wrong with your code.

    Instead of using @, you should disable error_reporting and display_errors just display_errors in php.ini

    #4751
    Helpful
    Up
    0
    Down
    Not Helpful

    admin
    Keymaster

    The @ is a way to tell that you don’t want to print error messages. It’s a bad practice because you might have an error and never see it because you just “hid” it.

    PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

    #4752
    Helpful
    Up
    0
    Down
    Not Helpful

    admin
    Keymaster

    @ Operator = Indicates that if there is any kind of error occur, then don’t display the message in the user’s browser. There are people who test this and didn’t see the difference even they put the @ or not they still don’t see any error in the browser, well just to add up, the reason why this happen is because of the setting in the php.ini file for error output is turn off.

    Different hosting company have different setting so to make sure that you don’t want to see any ugly script error for the users or hackers(for them to give a clue to infiltrate you site) you can always use the @ operator.

    Hope this help.

    #4753
    Helpful
    Up
    0
    Down
    Not Helpful

    admin
    Keymaster

    The @ is a way to tell that you don’t want to print error messages. It’s a bad practice because you might have an error and never see it because you just “hid” it.

    PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.