Php function extraction

Source: Internet
Author: User
[Switch] php function reference is reprinted from? Is hosserer finally edited? Hosserer? An image metaphor: Reference: You are my shadow, what I wear, what I wear, and what I wear. you are unset, and I am still me. Pass value: You are a photo of me at a certain time, or you are an independent thing. I said you are an apple, and you are an apple. it has nothing to do with me. Reprinted as follows :? The & amp; symbol added before the php function indicates [conversion] php function reference.

Reprinted from? Hosserer

Final editing? Hosserer

?

An image metaphor:

Reference: You are my shadow, my clothes, and your clothes. you are unset, and I am still me.

Pass value: You are a photo of me at a certain time, or you are an independent thing. I said you are an apple, and you are an apple. it has nothing to do with me.

Reprinted as follows:

?

The "&" symbol added before the php function indicates that the function is referenced and returned. what is the role of adding & symbol before the php function?

Php code?

Function & test ()
{
Static $ B = 0; // declare a static variable
$ B = $ B + 1;
Echo $ B;
Return $ B;
}

$ 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 (); // The value of $ B is 6?
The following explains:
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 .)

The example above is as follows:
$ 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 ......


What is the meaning of adding the & symbol before the php variable?

First look at an example

Php code?
$ Foo = 321 ;???
$ Bar = & $ foo ;????
$ Bar = 123 ;???
Print $ foo;

$ Foo = 321;
$ Bar = & $ foo ;?
$ Bar = 123;
Print $ foo; what is the output result?

Php code?
123 ????

Why?

Changing new variables will affect the original variables. this assignment operation is faster.
Note: Only named variables can assign values to addresses.
That is to say, if the value of $ bar is changed, the value of $ foo is changed.

Related Article

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.