gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php接口中interface存在的意义

来源:http://erdangjiade.com/topic/2198.html 你好,世界。 2017-09-25 22:42浏览(7)

本篇文章是对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中的某个方法注释掉,发现再调用的时候,就没用了

以上就是php接口中interface存在的意义的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2