English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The three major features of PHP: encapsulation, inheritance, and polymorphism

1. Encapsulation

Purpose: to make the class more secure

Method: member variables are made private, and operate indirectly through methods, with restriction conditions added in the methods

2. Inheritance

Concept: A subclass can inherit everything from the parent class

Method overriding: Method overriding in the subclass

Characteristics: Single inheritance: A subclass can have multiple parent classes, and a parent class can give rise to multiple subclasses

Override: Method overriding

Overload: Overloading, editing polymorphism

3. Polymorphism (runtime polymorphism)

Concept: The parent class refers to an instance of the subclass, since the subclass overrides the methods of the parent class, the different states displayed by the parent class reference when calling the method

Condition:

1It must occur under inheritance

2It must be overridden in inheritance

3Parent class reference calls method

If a method needs a parent class parameter, you can pass an object of a subclass

Static

Ordinary members

Ordinary members belong to objects

Static members

Static members belong to the class

Keyword: static

The keyword self: represents the class itself within the class

Ordinary members cannot be called within static methods

Static members can be called within ordinary methods

Interface

Extremely abstract classes

Interfaces cannot contain member variables, only member methods

Member methods can have no function body

Interface keyword: interface

Classes that implement interfaces must implement all methods inside the interface

Loading class:

include("./Ren.class.php");
include "./"Ren.class.php";
require("./Ren.class.php");
require "./"Ren.class.php";
require_once("./Ren.class.php");
require_once "./"Ren.class.php";

Automatic loading class methods

All class files must be placed in the same directory

The naming rules of all class files are consistent

That's all for this article. I hope the content of this article can bring some help to your learning or work, and I also hope to get more support for the Yell Tutorial!

Declaration: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You may also like