When declaring a member attribute in a class, there must be a modifier before it. When you are not sure which word to use, use var or public to save only one class, and the file name contains the class name.
When declaring a member attribute in a class, there must be a modifier before it. When you are not sure which word to use, use var or public to save only one class, and the file name contains the class name.
The Code is as follows:
/* Class declaration
* 1. What are you developing and are you sure you want to write?
* 2. The members in the class must belong to this class.
* [Modifier class keywords] class name {
* Member attributes:
* Member method:
*}
* 3. When declaring a member attribute in a class, there must be a modifier first. When you are not sure which word to use, use var or public
* Only one class is saved in a file. The file name contains the class name. File: class Name. class. php
* Write the Class Name:
* Variable: aaaBbbCcc
* Function: aaaBbbCcc
* Constant: AAABBBCCC
* Class Name: AaaBbbCcc
* 4. Member attributes in the class. If multiple objects have different attribute values when they are created, do not directly give the initial values.
*
*
* Instantiate objects through classes
* 1. Create an object with the new class name, which is the object of the created class.
* $ Object reference = new class name;
* 2. If there is a new keyword that is used to create an object, creating an object is to allocate a space in the memory.
*
* Only objects are stored in the same bucket.
*
* Object functions
*
* Allocate objects in memory
*
* Object usage
* Members of an object must be accessed through object references.
* Object> Member
*
* Object> member attributes
* Object> member Method
*
*
*
*/
// Class declaration (telephone class)
Class Phone {
// Declare attributes
Var $ pinPai;
Var $ color;
Var $ batteryCapacity;
Var $ screenSize;
// Member Method
Function call (){
}
Function message (){
}
Function playMusic (){
}
Function photo (){
}
}
// Class instantiation
Class Person {
Var $ name;
Var $ age;
Var $ sex;
Function say (){
}
Function eat (){
}
Function run (){
}
}
// Instantiate
$ P1 = new Person;
$ P2 = new Person;
$ P3 = new Person;
// Access Object Member
$ P1-> name = "zhangsan ";
Echo $ p1-> name;
?>