Class declaration and Instantiation

Source: Internet
Author: User
: This article mainly introduces the declaration and instantiation of classes. For more information about PHP tutorials, see. Declaration method

(Modifier keyword) class name {

Member attributes

Member method

}

Note:

1. a file only saves one class. the file name contains the class name. The advantage of such a name is that it facilitates automatic loading of programs in the future.

2. the members in the class must belong to this class.

3. modify keywords before member attributes. if you do not know what to add, use Var.

Instantiate object

$ Object name = new class name

Creating an object is allocating a space in the memory.

Access by members outside the object

Access through objects

$ Object name-> $ attribute name =

$ Object name-> $ method name ()

Access of members in the object

Is to access other methods and member attributes in the object method in the internal method of an object.

The object that uses the $ this keyword to call this method is equivalent to the first person "I"

$ This cannot be accessed outside the class

The above introduces the declaration and instantiation of classes, including the content, and hopes to help friends who are interested in PHP tutorials.

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.