Reference transfer-php reference is not a pointer. Let's see the output result.

Source: Internet
Author: User
{Code...} above is my own running result. In the manual, I do not know what to say: reference is not something as described above, and reference is not a pointer. This means that the following structure will not produce the expected results: {code...} This will make the $ var variable in the foo function be called in the function...
 
   

The above is my own running result.

In the manual, I don't know what to say:

Reference is not

As mentioned above, the reference is not a pointer. This means that the following structure will not produce the expected results:


  

This binds the $ var variable in the foo function to $ bar when calling the function, but is then re-bound to $ GLOBALS ["baz. It is impossible to bind $ bar to another variable within the function call range through the reference mechanism, because there is no variable $ bar in function foo (it is represented as $ var, but $ var only contains the variable content and does not call the name-to-value binding in the symbol table ).

In my understanding, $ c is already a reference, and PHP cannot assign another reference to it. If another reference is assigned to it, the reference $ c is automatically disconnected from the $ a variable, so two 2 values are output. I don't know if this is correct.

Reply content:
 
   

The above is my own running result.

In the manual, I don't know what to say:

Reference is not

As mentioned above, the reference is not a pointer. This means that the following structure will not produce the expected results:


  

This binds the $ var variable in the foo function to $ bar when calling the function, but is then re-bound to $ GLOBALS ["baz. It is impossible to bind $ bar to another variable within the function call range through the reference mechanism, because there is no variable $ bar in function foo (it is represented as $ var, but $ var only contains the variable content and does not call the name-to-value binding in the symbol table ).

In my understanding, $ c is already a reference, and PHP cannot assign another reference to it. If another reference is assigned to it, the reference $ c is automatically disconnected from the $ a variable, so two 2 values are output. I don't know if this is correct.

What you understand is correct. A reference is also a data type relative to an integer. If you assign another value to it, the original data is overwritten. In addition, this is why the unset () function can disconnect the reference.

I don't know what you mean.
But this is the standard result of the pointer in C.
The first parameter is a reference, but $ a is a variable. The variable memory size is 2, and & $ a is the pointer, & $ the value of expression a is the address of the memory.
In the first foo, if you pass $ a, it means 2, which is the address of.
And even in C Language foo (int * p), you call foo (& a); then you a = 2, and finally print a, and the output is also 2, your print star A (this star cannot be played )!

How can I change the external variable if you do not pass the address?
You have to transfer the address!
I really don't understand the reference in php. What is the difference between it and the pointer in c?

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.