Functions of the @ symbol in php and the role of the & symbol before the php function

Source: Internet
Author: User
What is the role of the @ symbol in php and the role of the & amp; symbol before the php function? Used to hide errors. 2. When will it be used? Some errors will abort the program, but in fact it may be just a local error. it is definitely not good because of a small error, therefore, adding a "@" in front of a possible error in your expectation can prevent the @ symbol in php and the & symbol before the php function from being caused by an error.

. Role? Used to hide incorrect
2. when should I use it? Some errors will abort the program, but in fact it may be just a local error. it is definitely not good because of a small error, therefore, you can add "@" in front of a possible error in your expectation to Prevent program suspension caused by errors. For example, "$ con = @ mysql_connect ($ MYhost, $ DB_name, $ DB_PassWord );"
3. what should I pay attention?
@ Is just a method to hide your ears and ears. it only hides errors, but does not solve them.

?

?

Answer to the second question:

?

?

The role of the & symbol before the php function:
Take a look at the following code. there is a & symbol before the function test.
Function & test (){
// Declare a static variable
Static $ B = 0;
$ B = $ B + 1;
Echo $ B;
Return $ B;
}
The call method and output result are as follows:
$ A = test (); // This statement outputs the value of $ B as 1.
$ A = 5;
$ A = test (); // This statement outputs the value of $ B to 2.
$ A = & test (); // This statement outputs the value of $ B to 3.
$ A = 5;
$ A = test (); // This statement outputs a value of 6 for $ B.
Note:
In this way, $ a = test (); does not actually return a function reference, which is no different from a common function call.
As for the reason: this is a PHP rule
PHP requires that $ a = & test (); is used to obtain the function reference and return.
As for what is reference return (in the php Manual, reference return is used when you want to use a function to find the variable on which the reference should be bound .)
This sentence in the manual may not be easy to understand. Read the following explanation:
$ A = test () is used to call a function. it only assigns the value of the function to $ a. any change made to $ a does not affect $ B in the function.
In the $ a = & test () method, the function calls the memory address of the $ B variable in return $ B and the memory address of the $ a variable,
Point to the same place.
This is equivalent to the effect ($ a = & B;). Therefore, the value of $ a is changed and the value of $ B is changed. Therefore, the following code is executed:
$ A = & test ();
$ A = 5;
Later, the value of $ B is changed to 5.

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.