Value assignment in variable 3 in php

Source: Internet
Author: User
Assignment method 1 in variable 3 in php, passing value assignment, for example, $ a = 1, $ B = $ a, etc;

2. assign values by reference. for example, $ a = & $ B, that is, $ a and $ B both point to the same storage variable value address in the memory;

3. Reference counting and passing values. all objects in php and js use the default value passing method to reference counting and passing values. The example is as follows:

Class Dog {

Public $ name = "Xiaohua ";

Public $ leg = 4;

}

$ A = new Dog; // at this time, $ a points to an address in the memory (assuming 0 XFFAD [1]), and the address points to the value of the final object.

$ B = $ a; // at this time, both $ B and $ a point to another address in the memory (0 XFFAD [2]), and the address points to the value of the final object.

Var_dump ($ B-> leg); // The result is int 4.

$ B = 999;

Var_dump ($ B); // The result is an int 999;

Var_dump ($ a); // The result is not int 999, but object (Dog) [1].

Public 'name' => string 'character �� '(length = 6) public 'leg' => int 4

From this we can see that the object's value passing method is a little different from the second reference value passing method.

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.