In-depth analysis of php interfaces and interface references_PHP tutorial

WBOY
Release: 2016-07-21 14:59:39
Original
877 people have browsed it

1. Introduction and creation of interfaces
Keywords: interface
2. References and specifications of interfaces
Keywords: implements
Interface : A special abstract class whose member attributes are all abstract, and have a standardized role in the program
1. All methods in the class are abstract
2. There is no need to add abstract before abstract methods
3. Interface abstraction The method attribute is public
4. The member attribute must be a constant

Abstract:
1. There is at least one abstract method in the class
2. Abstract must be added before the abstract method

Common points:
1. It cannot be instantiated, it must be inherited or referenced
2. After inheritance or reference, all abstract methods need to be overloaded before they can be used
Interface has its own creation keyword: interface is similar to the creation of ordinary classes

Copy code The code is as follows:

interface demo {
const NAME="name";
function Fun1();//All object methods are abstract methods, no need to add adstract in front
function Fun2();
}

Interfaces can use keywords: implements Multiple references separated by commas.
1. Common class reference interface examples:
Copy code The code is as follows:

class mypc implementations demo , demo2 , demo3{
……
}

2. Example of abstract class reference interface:
Copy code The code is as follows:

abstract class mypc implements demo , demo2 , demo3 {
...... 🎜>
The code is as follows:

class mypc extends root implementations demo , demo2 , demo3{ ……}
4 , interface and interface inheritance:

Copy code

The code is as follows:

interface demo3 extends demo{ … …
}
http://www.bkjia.com/PHPjc/328121.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/328121.htmlTechArticle

1. Introduction and creation keywords of interfaces: interface 2. References and specification keywords of interfaces: implements Interface: A special abstract class whose member attributes are all abstract. In the program, they are also...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template