服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - PHP教程 - 领悟php接口中interface存在的意义

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

2020-05-01 14:12PHP教程网 PHP教程

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

延伸 · 阅读

精彩推荐