Home  >  Article  >  Backend Development  >  Adding at in front of PHP is in line with the analysis of the role of @

Adding at in front of PHP is in line with the analysis of the role of @

高洛峰
高洛峰Original
2017-01-06 16:00:261044browse

When everyone is working on PHP projects, they always add the @ symbol before some lines of code. Does everyone know what it means? Let me share with you the analysis of the function of adding at before the function in PHP to match @

I used it today, so just remember it. In fact, it is an error control character. Even if an error occurs, the error message will be ignored and the following code will continue to be executed.

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

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

But if there is an error, for example, there is no page keyword after "index.php", and if $_GET['page'] does not exist, an error will be reported. If there is @, you can ignore this small error. .

Another example:

$conn = mysqli_conncet("q","w","e","r");

This will input error information about connecting to the database.

@$conn = mysqli_conncet("q","w","e","r");

If you add @ in front of $conn, you can prevent it from outputting error messages.

Just jot it down here.

The above is the analysis of the function of adding at in front of PHP to comply with @. I hope you like it.

For more relevant articles on the analysis of the role of adding at in front of PHP, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn