Abstract class --> Some kind of "structural form" that is more abstract than abstract class: interface; Interface: with"> PHP class interface technology (interface)-PHP Chinese Network Q&A
PHP class interface technology (interface)
A-王青召
A-王青召 2018-11-14 15:49:57
0
0
949
接口技术

What is an interface?

Look at the "development history" of interfaces:

Class--> Abstract class--> A certain "structural form" that is more abstract than abstract class: interface;

Interface: Analogy with abstraction:

There are only abstract methods and constants in the interface;

An abstract class can have abstract methods and other members;

Public $p2 = 2;

static $p3=3;

. . . ; . . . }

interface C1 {

const p1 = 1;

Abstract F3 (); The abstract class of the method is the same form!

However, the reason why it is called an interface is because it stipulates that interfaces can implement multiple inheritance;

##Use of interface:

The purpose of designing an interface is to allow "classes" to inherit it and use its constants and (abstract) methods.

When a class inherits one (or more) interfaces, it is not called inheritance, but called "implements",

That is: a class implements a certain interface(s) ;


## Form:

class class name [extends parent class name] implementations interface name 1, interface name 2,... {

… Definition of class members;

Inheritance of interface:

Interfaces can also inherit from each other - this is called inheritance;

Moreover, they can also perform multiple inheritance!

Indicative code:

Interface I1{.... }

Interface I2{.... }

Interface I3 extends I1, I2{

const PI = 3.14; Form: Same as the class, use the interface name and the "::" operator to "get";

echo I3::PI; //Output 3.14

##

A-王青召
A-王青召

不求惊动动地,但求无愧于人生!

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!