当前位置:网站首页>[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
边栏推荐
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- "The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
- Laravel post shows an exception when submitting data
- Power of leetcode-231-2
- JS中null NaN undefined这三个值有什么区别
- logback. XML configure logs of different levels and set color output
- Leetcode-136-只出现一次的数(用异或来解答)
- laravel post提交数据时显示异常
- How to implement backspace in shell
- PHP实现执行定时任务的几种思路详解
猜你喜欢

Vs tool word highlight with margin

Sysom case analysis: where is the missing memory| Dragon lizard Technology

【医学分割】attention-unet

全网“追杀”钟薛高

平衡二叉树(AVL)
![[Android -- data storage] use SQLite to store data](/img/f6/a4930276b3da25aad3ab1ae6f1cf49.png)
[Android -- data storage] use SQLite to store data

spark调优(三):持久化减少二次查询

水平垂直居中 方法 和兼容

Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition

如何快速检查钢网开口面积比是否符合 IPC7525
随机推荐
使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
Performance measure of classification model
预测——灰色预测
What is the difference between IP address and physical address
Laravel service provider instance tutorial - create a service provider test instance
打造All-in-One应用开发平台,轻流树立无代码行业标杆
HAVE FUN | “飞船计划”活动最新进展
logback.xml配置不同级别日志,设置彩色输出
Power of leetcode-231-2
Usage of config in laravel
[C language] question set of X
Communication mode between application program and MATLAB
pycharm 终端部启用虚拟环境
Laravel changed the session from file saving to database saving
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
Sysom case analysis: where is the missing memory| Dragon lizard Technology
Leetcode-136- number that appears only once (solve with XOR)
Xcode Revoke certificate
Imitate the choice of enterprise wechat conference room
three. JS create cool snow effect