Difficulties: Learn object-oriented ideas and syntaxes and understand ideas. PHP5 has added all basic object-oriented syntax to PHP5 compared to 4. I. object-Oriented programming ideology ObjectOriented (1) Event-centric programming ideology (2) Analysis of the steps required to solve the problem (3) implementation using functions (4) call when using II. what
Difficulties: Learn object-oriented ideas and syntaxes and understand ideas. PHP5 has added all basic object-oriented syntax to PHP5 compared to 4. I. object-Oriented programming ideology Object Oriented (1) Event-centric programming ideology (2) Analysis of the steps required to solve the problem (3) implementation using functions (4) call when using II. what
Difficulties: Learn object-oriented ideas and syntaxes and understand ideas.
PHP5 has added all basic object-oriented syntax to PHP5 compared to 4.
1. object-oriented programming ideology Object Oriented
(1) Event-centric Programming
(2) analyze the steps required to solve the problem
(3) Use functions to implement the steps
(4) called during use
2. What is an object?
(1) object
Represents specific things and abstract rules, plans, and events.
(2) Status and Behavior
Use data values to describe the status.
An action is an action of an object. It is used to change the state of an object.
Objects can be combined with data and operations to encapsulate data and objects in objects.
3. What is object-oriented
Object-oriented is a matter of functional division, not a step.
Focus on objects and the use of objects
Only object-oriented programs can truly conform to human thinking logic.
4. important advantages of object-oriented
Readability, reusability, stability, maintainability, and testability.
V. Relationship between classes and objects
The object is generated by class description. The attributes of an object are written in the class.
Each object in the same class is independent of each other.
Vi. Class Declaration
1. Simple format:
[Modifier] class name {// use the class keyword to add a space and the class name
[Member attributes] // also called member variables
[Member method] // also called a member function
}
2. Complete format:
[Modifier] class name [extends parent class] [implements interface 1], [interface 2]... {
[Member attributes] // also called member variables
[Member method] // also called a member function
}
3. Format
Modifier $ variable name [= default value]; // For example: public $ name = "zhangsan ";
Note: The member attributes cannot be expressions with operators, variables, methods, or function calls.
Correct definition method:
Common attribute modifiers: public, private, protected, static, and var (outdated)
I. Member Methods
1. Member method format:
[Modifier] function Method Name (parameter ..){
[Method body]
[Return value]
}
2. modifiers: public, protected, private, static, abstract, final
3. the declared member methods must be related to objects and cannot be meaningless operations.
Complete case:
8. Encapsulation
Encapsulation is to add modifiers to the member attributes and member methods of the object to hide the internal details of the object as much as possible to achieve access control for members (remember not to deny access)
Case:
9. Magic Methods
1. _ get ()
Automatic Call: it is automatically called when a private member is directly accessed!
If it is not a private attribute, you can pass the attribute name to the parameter.
In this way, each attribute returns a name and the output is as follows:
Or:
The output is as follows:
2. _ set ()
Automatic Call: two parameters are used when private attributes are directly set. One property name and one property value.
Output result:
3. _ isset ()
Automatic Call: When issset () is used to determine whether a private property exists, the _ isset () magic method is automatically called, and the parameter is the property name.
4. _ unset ()