当前位置:网站首页>[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
边栏推荐
- asyncio 概念和用法
- Leetcode-231-2的幂
- 121. The best time to buy and sell stocks
- The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
- Statistical learning method -- perceptron
- 【Vulnhub靶场】THALES:1
- Record the migration process of a project
- 爬虫(17) - 面试(2) | 爬虫面试题库
- Vs tool word highlight with margin
- [Android -- data storage] use SQLite to store data
猜你喜欢
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
3000 words speak through HTTP cache
Odoo集成Plausible埋码监控平台
数据中台落地实施之法
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Cesium(3):ThirdParty/zip. js
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Pycharm terminal enables virtual environment
Odoo integrated plausible embedded code monitoring platform
二叉搜索树(特性篇)
随机推荐
Three. JS series (1): API structure diagram-1
Laravel changed the session from file saving to database saving
两类更新丢失及解决办法
分类模型评价标准(performance measure)
模仿企业微信会议室选择
Description of vs common shortcut keys
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
laravel中将session由文件保存改为数据库保存
Logback日志框架第三方jar包 免费获取
What is the difference between IP address and physical address
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
记录Servlet学习时的一次乱码
47_ Contour lookup in opencv cv:: findcontours()
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
Imitate the choice of enterprise wechat conference room
Leetcode-136- number that appears only once (solve with XOR)
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
iptables只允许指定ip地址访问指定端口
How to implement backspace in shell
【Android -- 数据存储】使用 SQLite 存储数据