1. What are the keywords used for class definition in php? Class ?, Generally, the class name uses the upper-case classPeople {} 2. The attribute (data status) of the object is a variable defined in the class. You can use publicprivateprotect to declare the access permission. classPeople {public? $ Sex ;?? Public, can be freely accessed inside and outside the class pr
1. What are the keywords used for class definition in php? Class ?, General class names use uppercase class People {} 2. the attribute (data status) of an object is a variable defined in the class. You can use public private protect to declare the access permission. class People {public? $ Sex ;? ? // Public, pr can be accessed inside and outside the class at will
1. What are the keywords used for class definition in php? Class ?, General class names use uppercase letters
class People{}
2. the attribute (data status) of the object is a variable defined in the class, and the access permission can be declared through public private protect;
Class People {public? $ Sex ;? ? // Public, which can be freely accessed inside and outside the class. protect $ name = 'libi'; // protected, private $ age can only be accessed inside the class and in the subclass ;? ? //? Private, accessible only within the class}
You can use the-> symbol to call the attributes of an object ;? Use $ this-> to call the attributes of this object in the method.
3. The method in php5 uses function to define the method. The method name is generally lowercase;
4. Will the constructor automatically call this function during Object Instantiation for initialization? _ Construct ()? ? Parameters passed to the class when the sample object is passed to the constructor; explicit constructor can be used;
5. destructor: this function is executed when the object becomes garbage (no variable points to this object) or when a php thread ends and all objects in the current program are destroyed, is it the opposite of the constructor? _ Destruct ()
Unset () is used to destroy the variable pointing to the object;
6. What is the key word extends for class inheritance? The inherited class is called a subclass, And the inherited class is called a parent class or a superclass;
Use the keyword parent: In the subclass to call the method of the parent class.
7. Method Rewriting: when the method inherited from the parent class cannot meet the requirements of the subclass, You can override the method;
During method rewriting, the method to be rewritten must have the same method name. php5 does not limit the data type and parameters, and the return value;
The override method of the subclass cannot have more strict access than the parent class (the access permission of the override method of the subclass can only be loose than that of the parent class );
8. Overload )? PHP 5 does not support overloading.
Original article address: php object-oriented note (1). Thank you for sharing it.