: 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.