Php object-oriented basics, php object-oriented
Three main characteristics of the Face Image direction: encapsulation, inheritance, and polymorphism Abstraction:
When we first define a class, we actually extract the common attributes and behaviors of a class of things to form a physical model (Template). This method of research is called abstraction.
Encapsulation:
Encapsulation is to encapsulate the extracted data and the operations on the data, and the data is protected internally. Only authorized operations (methods) in other parts of the program can perform operations on the data.
Inheritance: inheritance is a subclass that persists the attributes and methods of the parent class through the parent class. polymorphism refers to multiple forms, which have the ability to express multiple forms. Objects are processed in different ways based on the object type. Polymorphism allows each object to respond to common messages in a suitable way. Polymorphism enhances the flexibility and reusability of software. class in object-oriented systems:
Class is used to describe an Object ):
Class describes the data that each object should contain, and class describes the behavior characteristics of each object.
Class member definition method:
Public $ aa; common, indicates global. This class can be accessed inside, outside, and subclass.
Private $ aa; private variable, accessible only to this class or subclass
Protect; protected variables, subclass can also be used
This is to define this object (instantiated object)
-> Get the xx in it, which is equivalent to.
Constructor method:
<? Phpclass jsq {public $ a; public $ B; public function _ construct ($ x, $ y) // _ construct () {} constructor, define a, B {$ this-> a = $ x; $ this-> B = $ y;} public function jia () directly here () {return $ this-> a + $ this-> B;} // AB instantiate public function jian () {return $ this-> a-$ this-> B ;} public function chen () {return $ this-> a * $ this-> B;} public function chu () {return $ this-> a/$ this-> B ;}$ suan = new jsq (3, 4); // class instantiation echo $ suan-> jian (); ?>
Everything is Object: Everything is an Object.