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.