在PHP中implement什么意思,php 接口,extends,implement,implements 作用及区别收集整理
标签:
extends 是继承某个类 ,继承之后可以使用父类的方法 ,也可以重写父类的方法,继承父类,只要那个类不是声明为final或者那个类定义为abstract的就能继承
implements 是实现多个接口,接口的方法一般为空的,必须重写才能使用,可以有效的对,实现的类 方法名,及参数进行约束。可以另类的实现多继承。
class A extends B implements C,D,E{} class中实现方法体。一个interface可以extends多个其他interface。
interface abc{
const bbq = 321;
public function a1(show $acc);
}
class test implements abc{
public function a1(show $acc){ //必须函数 and 参数
return 123;
}
}
$n = new abc();
echo $n->a1();
interface Comparable {
function compare(self $compare);
}
class String implements Comparable {
private $string;
function __construct($string) {
$this->string = $string;
}
function compare(self $compare) {
if($this->string == $compare->string){
return $this->string."==".$compare->string."
";
}else{
return $this->string."!=".$compare->string."
";
}
}
}
class Integer implements Comparable {
private $integer;
function __construct($int) {
$this->integer = $int;
}
function compare(self $compare) {
if($this->integer == $compare->integer){
return $this->integer."==".$compare->integer."
";
}else{
return $this->integer."!=".$compare->integer."
";
}
}
}
$first_int = new Integer(3);
$second_int = new Integer(4);
$first_string = new String("foo");
$second_string = new String("bar");
echo $first_int->compare($second_int); // 3!=4
echo $first_int->compare($first_int); // 3==3
echo $first_string->compare($second_string); // foo!=bar
echo $first_string->compare($second_int); // 严重错误
implement 用来拓展方法使用。
//扩展新的Function
var a=function(){};
var b=function(){};
Function.implement({
alert:function(msg){//直接alert输出内容
alert(msg);
},
output:function(msg){//firebug的控制台会输出内容,IE会报错
console.log(msg);
}
});
a.alert(‘1‘);
a.output(‘2‘);
b.output(‘3‘);
标签:
在PHP中implement什么意思,php 接口,extends,implement,implements 作用及区别收集整理相关推荐
- python类方法中使用:修饰符@staticmethod和@classmethod的作用与区别,还有装饰器@property的使用
python类方法中使用:修饰符@staticmethod和@classmethod的作用与区别,还有装饰器@property的使用(3-20181205) 文章目录: 一. @staticmetho ...
- JSP中response,session,cookie,application的作用及区别
目录 1.response :响应对象 2.session(服务端) 3.使用Cookie实现 记住用户名 功能 4.session :会话 5.session机制: 6.session: 7.ses ...
- JAVA中extends 与implements区别
JAVA中extends 与implements有啥区别? 1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口. exte ...
- java中extends与implements的区别
JAVA中extends 与implements有啥区别? 1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口. ...
- JAVA中extends与implements详解
JAVA中extends与implements有啥区别? 1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口. exten ...
- Wordpress模板主题中functions.php常用功能代码与常用插件[ 后台篇](持续收集整理)
用Wordpress建站的初学者一定会需要用到的Wordpress模板主题中functions.php常用功能代码与常用插件.慢慢持续收集整理....... 目录 一.Wordpress模板主题中fu ...
- Android 10 中有关限制非 SDK 接口的更新
Android 10 中有关限制非 SDK 接口的更新 目录 浅灰和深灰列表的命名发生变化 非 SDK 接口的代码注释 在 Android 10 中授予对非 SDK 接口的访问权限 Android 1 ...
- C++中模块(Dll)对外暴露接口的方式
总结下C++中模块(Dll)对外暴露接口的方式: (1)导出API函数的方式 这种方式是Windows中调用DLL接口的最基本方式,GDI32.dll, User32.dll都是用这种方式对外暴露系统 ...
- c调用c++ qt_C++中是如何调用C接口的?
前言 如何在C++代码中调用写好的C接口?你可能会奇怪,C++不是兼容C吗?直接调用不就可以了?这里我们先按下不表,先看看C++如何调用C代码接口. C++如何调用C接口 为什么会有这样的情况呢?想象 ...
最新文章
- 7.1 pdo 宝塔面板php_小白入门基础傻瓜式操作PHP面板安装使用_Bt宝塔面板
- ICLR论文盲审大反转:三个“8”完美过关,又来两个“1”彻底拒绝
- 用 Flask 来写个轻博客 (11) — M(V)C_创建视图函数
- 数据中台实战(六):交易分析
- object-c 队列
- Ubuntu中运行pip时报错
- Java中关于Arrays.sort的两种重载方法的理解
- 运用代码管理段来提升开发效率
- YUV测试序列下载地址
- docker gpu报错Error response from daemon: could not select device driver ““ with capabilities: [[gpu]]
- Ubuntu无法安装Xmind rpm包
- 使用el-checkbox实现全选,点击失效没有反应 1
- 最小发射功率下WSN的连通性和覆盖率
- 模糊层次分析法matlab,求三角模糊数层次分析法(FEAHP)模型计算的MATLAB程
- 用友U8 13.0运维及操作手册全版
- cad计算机忘了保存,cad图纸没保存怎么恢复(电脑突然断电,怎么找回未保存的CAD?)...
- 网络协议篇之CWMP协议(一)—— CWMP(TR-069)基础
- 开放平台及其技术架构
- 欧创芯原装OC 6700B升压型恒流驱动芯片,智能过温保护,内置 VDD 稳压管
- 怎么缩小照片的kb大小?