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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解领悟php接口中interface存在的意义的相关内容吗,在本文为您仔细讲解php interface的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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中的某个方法注释掉,发现再调用的时候,就没用了

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们