PHP operator (vii) "error control operator" Example explained

Source: Internet
Author: User
Tags php operator
Today, let's explain the error control operator in the PHP operator.

First, let's look at what the error control operator does.

The error control operator, as the name implies, is used to control the error output, which simply masks the error message and does not show it, not a real resolution of the error.

The way to use it is simply to add "@" to the wrong expression.

You can use this operator to mask some unnecessary error messages when you use certain functions frequently in your program, provided that this error message does not affect the operation of the program. We do not recommend the use of error controls for errors that affect program operations, which is detrimental to the elimination of program errors.

Here is a place to note that our "@" error control cannot be placed before the definition of a function or class, nor can it be used in terms of conditional structure. The "@" control is only valid for an expression, and the simple point is that if you get a value from a place, we can put the @ in front of it. For example, put @ in front of variables, constants, and function calls.

Let's take a look at the usage examples of error control operators

When we open a nonexistent file, we use "@" to mask the output of the error message.

When "@" is not used;

<?php$open_file = fopen ("index.php", "R");? >

The following output will be available:

Above is a warning error message, the approximate meaning of the index.php "This file does not exist." Error message on line three ...

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

<?php$open_file = @fopen ("index.php", "R");? >

So that we do not have the error message output, of course, this error still exists, but can not see it.

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

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.