PHP中new static()与new self()的区别及5.2版本重写5.3
来源:互联网 发布:适合苹果电脑的软件 编辑:程序博客网 时间:2024/05/17 00:01
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
5.2替换5.3 return new static($val);
用 get_class($this); 代码如下:
class A {
public function create1() {$class = get_class($this);
return new $class();
}
public function create2() {
return new static();
}
}
class B extends A {
}
$b = new B();
var_dump(get_class($b->create1()), get_class($b->create2()));
/*
The result
string(1) "B"
string(1) "B"
*/
参考http://www.jb51.net/article/54167.htm
阅读全文
0 0
- PHP中new static()与new self()的区别及5.2版本重写5.3
- PHP中new static()与new self()的区别
- PHP中new static()与new self()的区别
- PHP中new static()与new self()
- PHP中new static() 和 new self() 的区别
- PHP中new self()和new static()的区别探究
- PHP中new self()和new static()的区别
- PHP 中 new static 和 new self 的区别
- new self 与 new static 的区别
- new self() 与new static()的区别
- PHP中new static()与new self()的区别异同分析
- PHP中new static()与new self()的区别异同分析
- PHP中new static()与new self()的区别异同分析
- PHP中new static()与new self()的区别异同分析
- PHP中new static()与new self()的区别异同分析
- 【PHP趣味】new self和new static的区别
- PHP中new static() 和 new self()
- PHP的self::与static::,new self()和new static()之分
- SSM整合
- 流媒体
- $.ajax的修改或重写,需要用jQuery.ajaxSetup()
- Effective STL 45
- 浅谈Android系统开发中LOG的使用
- PHP中new static()与new self()的区别及5.2版本重写5.3
- LeetCode-74. Search a 2D Matrix
- TCP/IP三次握手四次挥手详解
- 征信莫名就黑了,黑了之后该怎么办?
- Keil MDK从未有过的详细使用讲解
- java 3笔记
- php 接口安全检查--防止url链接或者接口地址暴露后,网站被恶意攻击
- 使用Navicat Premium将Oracle数据库中的表和数据迁移到MySQL数据库中,遇到的Date类型出现精度问题及解决方法
- 什么叫"定向广告"?定向传播有哪些好处