Usage of the at (@) symbol in php

Source: Internet
Author: User
For beginners of php, it is often seen that there is an at (@) symbol in front of a function name, but they do not know its role and usage. after removing it, it seems that it has no effect on the program, I am very confused. Simply put, @ can ignore errors. the incorrect conversion function is the error control operator. the following describes its usage. For beginners of php, it is often seen that there is an at (@) symbol in front of a function name, but they do not know its role and usage. after removing it, it seems that it has no effect on the program, I am very confused. Simply put, @ can ignore errors. the incorrect conversion function is the error control operator. the following describes its usage.

For example:
Function db_connect () // connect to the database
{
@ $ Db = mysql_connect ('localhost', 'root', 'test ');
If (! $ Db)
Throw new Exception ('failed to connect to the database! Please try again! ');
Mysql_select_db ('book ');
Return $ db;
}

If the connection to the database fails, the previous "@" will be able to suppress the error, that is, it will not display the error, and then throw an exception to display its own exception handling, this is just to make the page viewer invisible. unfriendly pages cannot suppress errors, but can only Suppress display errors! @ Is used in the place where you think an error may occur in the future. @ a space will be placed next to it! It is better to use less, as if to increase the system overhead. For beginners of php, it is often seen that there is an at (@) symbol in front of a function name, but they do not know its role and usage. after removing it, it seems that it has no effect on the program, I am very confused. Simply put, @ can ignore errors. the incorrect conversion function is the error control operator. the following describes its usage.

For example:
Function db_connect () // connect to the database
{
@ $ Db = mysql_connect ('localhost', 'root', 'test ');
If (! $ Db)
Throw new Exception ('failed to connect to the database! Please try again! ');
Mysql_select_db ('book ');
Return $ db;
}

If the connection to the database fails, the previous "@" will be able to suppress the error, that is, it will not display the error, and then throw an exception to display its own exception handling, this is just to make the page viewer invisible. unfriendly pages cannot suppress errors, but can only Suppress display errors! @ Is used in the place where you think an error may occur in the future. @ a space will be placed next to it! It is better to use less, as if to increase the system overhead.

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.