PHP operator (7) example of "error control operator"

Source: Internet
Author: User
Tags php operator
The error control operator, as its name implies, is used to control error output. this control only shields error information and prevents it from being displayed. it does not actually solve the error. The method is simple, that is, add "@" before the wrong expression. Today, I will explain the" Error Control Operator".

First, let's take a lookErrorWhat are the control operators?

The error control operator, as its name implies, is used to control error output. this control only shields error information and prevents it from being displayed. it does not actually solve the error.

The method is simple, that is, add "@" before the wrong expression.

You can use this operator to block unnecessary error messages when using some functions in a program, provided that this error message does not affect the running of the program. If errors that affect program operations are not recommended, it is not conducive to eliminating program errors.

Note that the "@" error controller cannot be placed before the function or class definition, or used in the condition structure. The "@" control operator is only valid for the expression. Simply put, if a value is obtained from a place, we can put @ in front of it. For example, place @ in front of variables, constants, and function calls.

Let's take a look at it.Use of error control operators

When we open a non-existent file, we use "@" to block the output of error messages.

When "@" is not used;

 

The following output is displayed:

However, when "@" is used. This error message will not appear. The implementation code is as follows.

 

In this way, no error information is output. of course, this error still exists, but cannot be seen.

The above example is a simple application of the "@" error control operator. In the next section, we will introduce the ternary operators in PHP operators in detail.

Recommended articles:

1. PHP operator (1) "arithmetic operator" example

2. PHP operator (2) "string operator"

3. PHP operator (3) "value assignment operator" example

4. PHP operator (4) "bit operator" example

5. PHP operator (5) "logical operator" example

6. PHP operator (6) "comparison operator" example

The above is the details of the PHP operator (7) "error control operator" instance. For more information, see other related articles in the first PHP community!

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.