Home > Article > Backend Development > What is the difference between foo() and @foo() in php
The difference between "foo()" and "@foo()" in php: "@foo()" is the error control output, all errors will be ignored, "foo()" is the normal call output . "@" is the error suppressor. When placed before a PHP expression, all error reports for the expression will be ignored.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Operation The difference between Foo() and @foo() is that
@foo() is the error control output, and foo() is the normal call output.
@ is an error suppressor; when placed before a PHP expression, all errors in the expression will be ignored; the
@ symbol can ignore error reports in PHP, for expressions Some prompt errors, but some do not affect statement execution. You can add @ before the expression.
You can put the @ symbol before variables, functions, include() calls, constants, etc., but you cannot put @ before the definition of functions and classes, nor can it be used before conditional structure statements
eg: if, switch, while, for and foreach, etc.
Extension: All PHP operator test points
1) PHP operator precedence (from high to low)
- increment/decrement
- !
- arithmetic operator
- Size comparison
- (Not)Equality comparison
- Quote
- Bit operator (^)
- Bit operator (|)
- Logic and
- Logic or
- 三目
- Assignment
- and
- xor
- or
Note: The use of brackets can increase the readability of the code. It is recommended to use
2) Compare Operator: The difference between ==
and ===
- == Comparison value is equal; === Comparison value Whether they are equal and whether their types are the same.
- Equal value judgment (seven cases of FALSE)
if ('== false') {
echo '';
} elseif ('0' == 0 ) {
echo '';
} elseif (0.0 == 0) {
echo '';
}
Note:
- All seven cases of FALSE are satisfied:
- Integer type 0
- Floating point type 0.0
- Zero string '0'
- Empty string'' "
- Empty array array()
- null
- Boolean false
3) Increment/decrement operator
- The increment/decrement operator does not affect Boolean values;
- true ; // true
- true–; // true
- false ; // false
- false–; // false
- Decrementing the NULL value has no effect; incrementing the NULL value is 1;
- NULL–; // NULL
- #NULL; // 1
- If increment and decrement come first, they will be operated first and then returned; otherwise, they will be returned first and then operated
4) Logical operators
① Short circuit effect
$a = true || $b == 3; // 前面是 true,后面不会执行【|| : 一真为真】 $b = false && $a == 1; // 前面是 false,后面不会执行【&&:一假为假】
② ||
and &&
have different priorities than or
and and
// 先执行 false || true,得到 true,再赋值给 $a $a = false || true; // $a = true; // 先执行 $b = false,整体为 true,则 $b的值为 false $b = false or true; // $b = false;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the difference between foo() and @foo() in php. For more information, please follow other related articles on the PHP Chinese website!