当前位置:网站首页>[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
边栏推荐
- 【DesignMode】代理模式(proxy pattern)
- laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
- Tragedy caused by deleting the console statement
- MySQL中, 如何查询某一天, 某一月, 某一年的数据
- 95. (cesium chapter) cesium dynamic monomer-3d building (building)
- The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
- 【Android -- 数据存储】使用 SQLite 存储数据
- Leetcode-136-只出现一次的数(用异或来解答)
- SqlServer2014+: 创建表的同时创建索引
- Opportunity interview experience summary
猜你喜欢
二叉搜索树(基操篇)
无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
平衡二叉树(AVL)
torch.numel作用
Logback logging framework third-party jar package is available for free
Odoo integrated plausible embedded code monitoring platform
Statistical learning method -- perceptron
AutoLISP series (3): function function 3
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Pycharm terminal enables virtual environment
随机推荐
Opencv personal notes
logback.xml配置不同级别日志,设置彩色输出
MySQL中, 如何查询某一天, 某一月, 某一年的数据
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
Markdown formula editing tutorial
统计学习方法——感知机
无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
【MySql进阶】索引详解(一):索引数据页结构
Leetcode-136-只出现一次的数(用异或来解答)
null == undefined
网关Gateway的介绍与使用
全网“追杀”钟薛高
Balanced binary tree (AVL)
URL和URI的关系
Laravel changed the session from file saving to database saving
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
Three. JS series (1): API structure diagram-1
修改配置文件后tidb无法启动
Introduction to ThinkPHP URL routing