Instructions for using the at @ symbol in PHP _php tutorial

Source: Internet
Author: User
I believe a lot of PHP and I like the new students in the study of PHP and I like, are depressed over this problem. @ (at) What exactly does this sign do?


Once, download other people's source view, see Countless @ marks, began to think is a comment, and later found that the statement behind the @ will also be executed. Wondering, what is the mark doing?

With the continuous deepening of learning, it is finally clear. The function of this notation is somewhat similar to the Ignore error "On Error Resume Next" in ASP. Their role is the same, when the PHP interpreter encounters the statement at the beginning of the @, regardless of whether our statement is successful, the subsequent statements will continue to execute, without error. However, it is important to note that the @ (at) tick only works on the current line.



I hope the question about @ is here.

eg. The following statement must be an error.

Error code

The code is as follows Copy Code

$sql = mysql_connect (*);
?>

However, if we add the @ (at) Mark, we will not get an error and continue to execute.

No error code

The code is as follows Copy Code

@ $sql = mysql_connect (*);
echo "I have been executing";
?>


Continue executing the code below.

The code is as follows Copy Code

@ $page =$_get[' page ']?intval ($_get[' page '): 1;

This is the value from the URL to get the page keyword, such as "index.php?page=5", then the $page will be taken to 5.

But if there is an error, such as "index.php" after the page keyword, if you go to fetch $_get[' page ' does not exist will be an error, then there is @ can ignore this small error.

Another example:

The code is as follows Copy Code

$conn = Mysqli_conncet ("Q", "W", "E", "R");

This will enter an error message about connecting to the database.

The code is as follows Copy Code

@ $conn = Mysqli_conncet ("Q", "W", "E", "R");

If the $conn is preceded by the @, you can not let him output the error message.

http://www.bkjia.com/PHPjc/628691.html www.bkjia.com true http://www.bkjia.com/PHPjc/628691.html techarticle I believe a lot of PHP and I like the new students in the study of PHP and I like, are depressed over this problem. @ (at) What exactly does this sign do? Once, download other people's Source view, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.