Php learning note class declaration and object instantiation. Copy the code as follows :? Php * 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 {
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;
?>
The http://www.bkjia.com/PHPjc/323522.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323522.htmlTechArticle code is as follows :? Php/* 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 {...