Home > Backend Development > PHP Tutorial > Instructions on the role of the at @ symbol in php_PHP tutorial

Instructions on the role of the at @ symbol in php_PHP tutorial

WBOY
Release: 2016-07-13 17:16:12
Original
1245 people have browsed it

I believe that many new PHP users like me have been frustrated by this problem when they were learning PHP. What exactly does the @(at) symbol do?


Once, I downloaded someone else's source code and looked at it. I saw countless @ marks, and I thought they were comments at first; later I found that the statements after @ will also be executed. I'm confused, what is this mark for?....

As the study continues to deepen, I finally understand. The function of this mark is somewhat similar to the ignored error "on error resume next" in ASP. Their functions are the same. When the PHP interpreter encounters a statement starting with @, regardless of whether the statement in this line is executed successfully, it will continue to execute subsequent statements without reporting an error. But please note that the @(at) mark only works on the current line.



I hope the question about @(at) ends here.

eg. The following sentence will definitely report an error

Error code

The code is as follows
 代码如下 复制代码

$sql = mysql_connect(*);
?>  

 

Copy code

$sql = mysql_connect(*);

?>

 代码如下 复制代码

@$sql = mysql_connect(*);
echo "我一直在执行";
?>  


 代码如下 复制代码

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

However, if we add the @(at) mark, the error will not be reported and execution will continue.

No error code

?>
The code is as follows
 代码如下 复制代码

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

Copy code

 代码如下 复制代码

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

@$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 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. At this time, you can ignore this small error with @. Another example:
The code is as follows Copy code
$conn = mysqli_conncet("q","w","e","r"); This will input error information about connecting to the database.
The code is as follows Copy code
@$conn = mysqli_conncet("q","w","e","r"); If you add @ in front of $conn, you can prevent it from outputting error messages.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628691.htmlTechArticleI believe that many new PHP users like me have been frustrated by this problem when they were learning PHP. What exactly does the @(at) symbol do? Once, I downloaded someone else’s source code to see...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template