当前位置:网站首页>[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
边栏推荐
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- The difference and working principle between compiler and interpreter
- 深度监听 数组深度监听 watch
- 使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
- asyncio 概念和用法
- [flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
- Tragedy caused by deleting the console statement
- Continuous creation depends on it!
- Logback logging framework third-party jar package is available for free
- You Yuxi, coming!
猜你喜欢
Record the migration process of a project
Talk about the cloud deployment of local projects created by SAP IRPA studio
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
二叉搜索树(特性篇)
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
全网“追杀”钟薛高
What are compiled languages and interpreted languages?
删除 console 语句引发的惨案
【DesignMode】代理模式(proxy pattern)
1亿单身男女“在线相亲”,撑起130亿IPO
随机推荐
AutoLISP series (2): function function 2
Find tags in prefab in unity editing mode
C语言进阶——函数指针
Odoo integrated plausible embedded code monitoring platform
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
二叉搜索树(基操篇)
Tragedy caused by deleting the console statement
What else can an ordinary person do besides working in a factory to make money?
pycharm 终端部启用虚拟环境
Cesium (4): the reason why gltf model is very dark after loading
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
Power of leetcode-231-2
Logback logging framework third-party jar package is available for free
Personal notes of graphics (4)
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Sysom case analysis: where is the missing memory| Dragon lizard Technology
What about the pointer in neural network C language
thinkphp3.2.3中设置路由,优化url
网关Gateway的介绍与使用