How to transfer objects in PHP

Source: Internet
Author: User

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

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.