how the object is passed:
Why is it that for objects, value passing and reference passing, in this case they seem to have no difference???
This is to be understood from the way the object's data is stored:
$o 1 = new C1 (); Here you create an object O1, which stores the result:
Here, in fact, the variable $o 1 , the stored data is just an "object number #1", this object number, will point to the object data new C1 (); the number of data that we cannot control is just the internal distribution of the system.
then $o 2 = $o 1; as a value, the actual copy is the number of the object: The resulting scenario is:
In syntax, manipulating the properties of an object variable is actually done by pointing to the object with that number.
$o 1->P1 = 2; at this point, the object number #1 to modifythe internal data of the object (new C1()) itself .
Echo $o 2->p1; this is equivalent to acquiring the internal data of the object (new C1 ()) pointed to in the number #1 contained in the variable $o 2 P1
So, the corresponding reference is passed, and this is the case:
$o 3 = new C1 (); Another object is created, as shown below:
And then:
$o 4 = & $o 3; after the reference is passed, their relationship is illustrated by:
So:
$o 3->P1 = 2; //
Echo $o 4->p1; output 2
How to transfer objects in PHP