The function of the @ symbol in PHP and the & symbol before PHP function
. Role? Used to hide the wrong
2. When do I use it? Some of the errors will abort the program, but in fact it may only be a bug, because a small error and abort the program, it is certainly not good, so in the place where they expected to be wrong to add an "@", can prevent the error caused by the program to stop. For example "$con = @mysql_connect ($MYhost, $DB _name, $DB _password);"
3. What issues should be noted?
@ Just deceiving, it just hides the error, but it doesn't fix the error.
?
?
Answer to the second question:
?
?
The function of the & symbol before PHP function:
Look at the following code, which has a & symbol in front of the function test.
function &test () {
Declare a static variable
static $b = 0;
$b = $b +1;
Echo $b;
return $b;
}
The invocation method and the output result are as follows:
$a =test ();//This statement outputs a value of $b of 1
$a = 5;
$a =test ();//This statement outputs a value of $b of 2
$a =&test ();//This statement outputs a value of $b of 3
$a = 5;
$a =test ();//This statement outputs a value of $b of 6
Description
In this way $a=test () is not actually returned by a function reference, which is not the same as a normal function call.
As for the reason: this is the PHP rule
PHP rules through $a=&test (); The way to get is to return the reference to the function.
As for what is a reference return (the PHP manual says that reference return is used when you want to use a function to find out which variable the reference should be bound to.) )
This sentence on the manual may not be very well understood, see the explanations below:
$a =test () call the function, just assign the value of the function to $ A, and no change to $ A will affect the $b in the function.
And by calling the function by $a=&test (), his function is to return the memory address of the $b variable in the $b and the memory address of the $ A variable,
Point to the same place.
That produces the equivalent effect ($a =&b;) So change the value of $ A and change the value of $b at the same time, so in execution:
$a =&test ();
$a = 5;
Later, the value of the $b becomes 5