Classes and objects
Object: Everything can be considered an object, and an object is an instantiation of a class.
Class: A class is an abstraction of an object that describes a feature common to many objects.
Defining Classes Class
member variables and Member methods
Access modifier Public Private protected protected
Object-oriented three major features:
1. Encapsulation: Purpose: Protection class, procedure: Member private, method access. __get () __set ()
Construction method: Special point: 1. Special 2. The execution time is special; the initialization of the member can be implemented
$this Keyword: $this represents the Object
2. Inheritance: Subclasses can inherit everything from the parent class
Features: Single inheritance: A subclass can have only one parent class, and a parent class may derive multiple subclasses.
Method overrides: A method that has the same name as the parent class in the subclass overrides the parent class method, if you want to extend the method of the parent class instead of overwriting: Parent::say ();
3. Polymorphism: When the parent class refers to a subclass instance, the parent class reference is polymorphic when the method is called, because the child class overrides the method of the parent class.
Conditions: 1. Must inherit 2. Subclasses must override the parent class Method 3. Parent class reference to child class instance
Static
Keywords: static
An ordinary member belongs to an object.
A static member is a class-owned
Static members can be called in normal methods
Static methods cannot invoke ordinary members
Called with the class name: Ren::say ();
Self Keyword: represents the class itself
Abstract class
Keywords: abstract
Abstract classes cannot be instantiated and can be inherited
Interface
Keyword: interface, do not add class keyword
There are member methods inside the interface, but there is no function body.
Implements the keyword used by the interface: implements is not extends
Subclasses must implement all methods of the interface
Destructors
Special execution Special: Execute when object is destroyed
__tostring () method
Clone keyword: clone
7 Types of Load classes
function overloading
Requirements: 1. Either the number of parameters is different or the parameter type is different. 2. Method names must be the same
PHP Object-Oriented Essentials summary