Home > Backend Development > PHP Tutorial > Detailed explanation of PHP interface and reference interface_PHP tutorial

Detailed explanation of PHP interface and reference interface_PHP tutorial

WBOY
Release: 2016-07-13 17:41:15
Original
1090 people have browsed it

1. The introduction and creation of the interface
Keywords: interface

2, the reference and specifications of the interface
Keywords: Implements
Interface: A member attribute is all abstract special abstract categories , have the same normative role in the program
1. All methods in the class are abstract methods
2. There is no need to add abstract
before abstract methods. 3. The attributes of interface abstract methods are public
4. Member attributes must be Abstract for constants
:
1. There is at least one abstract method in the class
2. Abstract
must be added before the abstract method. Common points:
1. Neither of them can be instantiated. , must be inherited or referenced

2. After inheritance or reference, all abstract methods need to be overloaded before use
Interface has its own creation keyword: interface is similar to the creation of ordinary classes
interface demo {
const NAME="name";
function Fun1();//Object methods are all abstract methods, no need to add adstract
in front function Fun2();
}
interface You can use the keyword: implements to separate multiple references with commas.

1. Common class reference interface examples:
class mypc implements demo, demo2, demo3{

}
2. Examples of abstract class reference interfaces:
abstract class mypc implements demo, demo2, demo3{
 …
 }
3. Examples of coexistence of inherited parent class reference interfaces:
class mypc extends root implements demo , demo2 , demo3{
 …
}
4. Interface and interface inheritance:
interface demo3 extends demo{
 …
}

http://www.bkjia.com/PHPjc/486152.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486152.htmlTechArticle1. 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, the same...
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