Reference Pass-PHP reference is not exactly what the pointer is, look at this output result

Source: Internet
Author: User
 
  
   

The above is the result of my own operation.

That's what the manual says, don't know what to say:

Reference is not what

As mentioned earlier, references are not pointers. This means that the following structure does not produce the effect you expect:


  
   

This causes the $var variables in the Foo function to be bound together with the $bar when the function is called, but is then re-bound to the $GLOBALS ["Baz"]. It is not possible to bind $bar to other variables within the scope of a function call by means of a reference mechanism, because there is no variable $bar in the function foo (it is represented as a $var, but $var only the contents of the variable without calling the name-to-value binding in the symbol table).

Its own understanding is that $c is already a reference, and PHP does not allow it to be assigned another reference. If you assign another reference to it, the reference $c is automatically disconnected from the $ A variable, so the output is two 2. I don't know if that's right.

Reply content:

 
  
   

The above is the result of my own operation.

That's what the manual says, don't know what to say:

Reference is not what

As mentioned earlier, references are not pointers. This means that the following structure does not produce the effect you expect:


  
   

This causes the $var variables in the Foo function to be bound together with the $bar when the function is called, but is then re-bound to the $GLOBALS ["Baz"]. It is not possible to bind $bar to other variables within the scope of a function call by means of a reference mechanism, because there is no variable $bar in the function foo (it is represented as a $var, but $var only the contents of the variable without calling the name-to-value binding in the symbol table).

Its own understanding is that $c is already a reference, and PHP does not allow it to be assigned another reference. If you assign another reference to it, the reference $c is automatically disconnected from the $ A variable, so the output is two 2. I don't know if that's right.

What you understand is right. A reference is also a data type that is relative to an integer, a floating-point type, and assigns another value to it, of course, to overwrite the original. Another reason why the unset () function can break a referenced relationship is this.

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 passes the variable, and the variable memory content is 2,& $a is the pointer,& $a expression is the value of a represents the memory address
The first foo you pass a $ A is a 2, which is the address of a.
And even if the C language foo (int *p) you call Foo (&a), and then you a=2, finally in print a, he output is also 2 Ah, your print star A (this star can not be hit)!

How can you change an external variable without sending an address?
You have to pass the address!
I really don't understand the reference in PHP, and what's the difference between a 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.