Class
A class is a definition or code template used to activate an object. You can read and modify this code, but it will exist as an object when executed. In actual code, each time a class is used, a copy of an object is generated.
Object
An object is the form in which the class is copied and activated. "Instance" refers to an object with a unique name copy in the memory. In PHP, the keyword "new" is required to instantiate a class as an object.
Method
The method is actually a function written in the class definition section. In PHP, a method refers to a function definition written in a class implemented by a function.
Attribute
Attribute refers to the variable in the class definition section.
Polymorphism
In object-oriented programming, two independent classes are allowed to have common interface names, such as methods and attributes, instead of using other methods. Therefore, even if both classes have print methods, PHP does not bother with this, mainly because the object name is unique.
Encapsulation
The unique purpose of encapsulation is to allow external users to influence the protected data (that is, attributes) within a class by using a specific method of the class to manage the internal attributes of the class ).
Inheritance
Object-Oriented Programming allows classes to be copied or inherited from known base classes (also called parent classes. If you have a class named person and define some methods and attributes, you want to create another class, the term person, but lemberjack. You can use all attributes of the person class, for example, the height, name, and eye color can be extended to lumberjack, saving time and improving efficiency.
There are two functions in PHP called magic methods. They are automatically executed, which is a pre-defined method. The magic Method Used as the constructor of a class does not allow return values.
1. _ construct will be triggered each time it is instantiated.
2. _ destruct is called every time the object is removed from the memory or the script ends.
Variable $ this
$ This is a variable that defines the internal reservation of an object. It does not need to be defined in advance. When the class is instantiated into an object, it will exist. It uses the "$ this-> Object Name" method to reference the relevant properties of the internal visible class.
Public, protected, and private
Public entities can be used and accessed in all scopes;
The protected object can only be accessed by the class itself and its parent class or its subclass;
Private entities can only be accessed by the class itself.
Encapsulation is a concept that internal entities of a class are immune from external influences. Of course, private scope attributes can achieve this goal most. Basically, setting a restricted access scope is the best way to avoid external changes, especially when you write a class library that will be used by many different projects, or when creating a commercially available version class library.
Protected (protected) scopes are rarely used unless you want to benefit from a series of hierarchical object trees (that are, inherited classes. If no scope identifier is defined, it is public by default. It is recommended that all interface methods requiring external access be public. The best way for a class to share information externally is to set the attribute to private and set the public get and set methods.
Get and set accessors
This concept allows more interfaces to be protected within the scope of the class. Each class attribute has its own get and set methods, and each attribute can only be affected through these access methods.