您的位置:首页 > 编程语言 > PHP开发

个人悟出php接口中interface存在的意义

2012-08-29 14:04 465 查看
可能大家都懂这些,作为不懂的我猜测了一下这个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中的某个方法注释掉,发现再调用的时候,就没用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  interface php function class