PHP new self与new static
2015-12-04 16:45
609 查看
self refers to the same class whose method the new operation takes place in.
static in PHP 5.3's late static bindings refers to whatever class in the hierarchy which you call the method on.
In the following example, B inherits both methods from A. self is bound to A because it's defined in A's implementation of the first method, whereas static is bound to the called class (also see get_called_class() ).
static in PHP 5.3's late static bindings refers to whatever class in the hierarchy which you call the method on.
In the following example, B inherits both methods from A. self is bound to A because it's defined in A's implementation of the first method, whereas static is bound to the called class (also see get_called_class() ).
class A { public static function get_self() { return new self(); } public static function get_static() { return new static(); } } class B extends A {} echo get_class(B::get_self()); // A echo get_class(B::get_static()); // B echo get_class(A::get_static()); // A
相关文章推荐
- PHP基础--分支语句和array操作
- firefox php 验证码图片 多次请求问题 待解决
- PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法
- PHP正则匹配取文章首图代码
- 修改文件上传大小限制
- 系统时间与NTP服务的相关使用
- 子查询语句的thinkphp实现
- PHPCMS V9 WAP手机门户域名绑定
- thinkphp3.2 分页方法和模板
- windows 2003 iis php
- PHP编译错误解决:Don't know how to define struct flock on this system, set --enable-opcache=no
- php基础算法集合
- ThinkPHP框架--身份证号码的验证类
- 常用的php数组函数
- 关于yii2的一些知识的学习笔述
- cookie.setPath()的用法
- PHP中date函数月和日带0问题
- PHP正则表达式语法汇总
- php分类
- deepin安装php7