PHP access and constructor for members of object 13

Source: Internet
Author: User
: This article mainly introduces the access and constructor of PHP object-oriented 13 object members. For more information about PHP tutorials, see. 1.1 access to members of an object

Access to member attributes includes assigning values and obtaining member attributes. The members in the access object are similar to the elements in the access array. You can only access each member of an object by referencing the object. $ Reference name = new class name ([parameter quantity list]); // object instantiation format $ reference name-> member attribute = value; // operation for assigning values to member attributes $ echo $ reference name-> member attributes; // obtain the value of member attributes $ reference name-> Member method; // access the member methods in the object

If the members in the object are not static, the "object reference name> attribute" or "object reference name> method" is a unique access form.

1.2 Special object reference "$ this"

Members in the access object must use the reference variable of the object, either outside the object or inside the object. However, after the object is created, the reference name of the object cannot be found in the object method. If you create an object by using the new keyword in the object method, the called member is also a member of the new object. Once an object is created, a special object reference "$ this" exists in each member method of the object ". $ This refers to the object to which the member method belongs. it is used to access members inside the object. Whether it is to use $ this inside the object to access members inside the object, or to access members in the object through the reference name of the object outside the object. All require special operators "->"
ClassPerson {var $ name; var $ sex; var $ age; functionsay () {echo "my name :". $ this-> name. "Gender :". $ this-> sex. "Age ". $ this-> age;} functionrun () {echo $ this-> name. "Walking
";}}

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above section describes the access and constructor of PHP object-oriented 13 objects, including some content, and hope to help those who are interested in PHP tutorials.

    Related Article

    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.