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

yipeiwu_com6年前PHP代码库
可能大家都懂这些,作为不懂的我猜测了一下这个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中CI操作多个数据库的代码

其实,这不是什么难事,因为刚入手CI,所以还是费了一番周折。好在有手册。 找到数据库配置文件,添加一个新的库的连接信息。$config[XX]。 在控制器里边,     a) $this...

有关phpmailer的详细介绍及使用方法

第一,需要下载PHPMailer文件包phpmailer. http://phpmailer.sourceforge.net/第二,确认你的服务器系统已经支持socket ,通过phpi...

php dirname(__FILE__) 获取当前文件的绝对路径

PHP 常量 dirname(__file__) __FILE__ :被称为PHP魔术常量 ,返回当前执行PHP脚本的完整路径和文件名,包含一个绝对路径 1)dirname(__FILE...

php 方便水印和缩略图的图形类

复制代码 代码如下:<?php /* *@author    夜无眠    27262681@qq....

自动分页的不完整解决方案

测试代码 <form id="form1" name="form1" method="post" action="">  &...