当前位置:网站首页>[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
2022-07-07 16:36:00 【weixin_ forty-three million two hundred and twenty-four thousan】
stay PHP The interface of , Interface can inherit interface . although PHP Class can only inherit one parent class ( Single inheritance ), But interfaces and classes are different , Interfaces can implement multiple inheritance , You can inherit one or more interfaces . Of course, interface inheritance also uses extends keyword , If you want more than one inheritance, just separate the inherited interfaces with commas .
It should be noted that when your interface inherits other interfaces , Directly inherit the static constant properties and abstract methods of the parent interface , So when a class implements an interface, it must implement all the relevant abstract methods .
Now you are right PHP Have you understood the inheritance of interfaces , The following examples are for reference , The code is as follows
<?php
interface father{
function shuchu();
}
interface fam extends father{
function cook($name);
}
class test implements fam{
function shuchu(){
echo " Interface inheritance , To implement two abstract methods ";
echo "<br>";
}
function cook($name){
echo " People who usually cook are :".$name;
}
}
$t=new test();
$t->shuchu();
$t->cook(" Mom ");
?>
result :
Interface inheritance , To implement two abstract methods
People who usually cook are : Mom
The above example is that the interface inherits an interface , So in test Class implementation fam Two abstract methods should be instantiated in the interface , It is to instance the abstract methods of the subclass and parent of the interface .
Let's take a look at an example of interface multi inheritance , The code is as follows :
<?php
interface father{
function shuchu();
}
interface mother{
function dayin($my);
}
interface fam extends father,mother{
function cook($name);
}
class test implements fam{
function dayin($my){
echo " My name is :".$my;
echo "<br>";
}
function shuchu(){
echo " Interface inheritance , To implement two abstract methods ";
echo "<br>";
}
function cook($name){
echo " People who usually cook are :".$name;
}
}
$t=new test();
$t->shuchu();
$t->dayin(" cockroach ");
$t->cook(" Mom ");
?>
result :
Interface inheritance , To implement two abstract methods
My name is : cockroach
People who usually cook are : Mom
边栏推荐
- 01tire+链式前向星+dfs+贪心练习题.1
- Leetcode-136-只出现一次的数(用异或来解答)
- JS中null NaN undefined这三个值有什么区别
- 【MySql进阶】索引详解(一):索引数据页结构
- prometheus api删除某个指定job的所有数据
- PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
- 【DesignMode】外观模式 (facade patterns)
- 【DesignMode】享元模式(Flyweight Pattern)
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- 【PHP】PHP接口继承及接口多继承原理与实现方法
猜你喜欢
95. (cesium chapter) cesium dynamic monomer-3d building (building)
网关Gateway的介绍与使用
【MySql进阶】索引详解(一):索引数据页结构
Personal notes of graphics (2)
What are compiled languages and interpreted languages?
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
3000 words speak through HTTP cache
Personal notes of graphics (1)
Horizontal and vertical centering method and compatibility
Opencv personal notes
随机推荐
How to query the data of a certain day, a certain month, and a certain year in MySQL
Geoserver2.18 series (5): connect to SQLSERVER database
Tragedy caused by deleting the console statement
Bidding announcement: 2022 Yunnan Unicom gbase database maintenance public comparison and selection project (second) comparison and selection announcement
47_ Contour lookup in opencv cv:: findcontours()
Description of vs common shortcut keys
作为Android开发程序员,android高级面试
Vs tool word highlight with margin
预测——灰色预测
Vs2019 configuration matrix library eigen
PHP实现执行定时任务的几种思路详解
Statistical learning method -- perceptron
Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例
Usage of config in laravel
Opportunity interview experience summary
What are compiled languages and interpreted languages?
删除 console 语句引发的惨案
Unity3d click events added to 3D objects in the scene
The difference and working principle between compiler and interpreter
URL和URI的关系