Home > php教程 > php手册 > 领悟php接口中interface存在的意义

领悟php接口中interface存在的意义

WBOY
Release: 2016-06-06 20:29:13
Original
1445 people have browsed it

本篇文章是对php接口中interface存在的意义进行了详细的分析介绍,需要的朋友参考下

可能大家都懂这些,作为不懂的我猜测了一下这个interface的意义,他就是为了后面调用的时候再调用的方法中调用实现类中interface中存在的内容,好绕口啊,写个例子留作以后看吧
pay.php

复制代码 代码如下:


interface Ipay
{
function withmoney();

//function withinternet();
}
class Dmeng implements Ipay
{

function withmoney()
{
echo "花人民币买东西";
}
function withinternet()
{
return "用网银支付";
}
}


usei.php

复制代码 代码如下:


include_once 'pay.php';
class main
{
function run($vc)
{
$this->vc = $vc;
$this->vc->withinternet();
echo "yunxing";
}

}
$com= new main();
$com->run(new Dmeng);


就是上面那样,虚拟主机,香港服务器,服务器空间,我们将interface中的某个方法注释掉,发现再调用的时候,就没用了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template