LOADING STUFF...

浅谈PHP中new self()和new static()的区别

技术教程10小时前发布 北陌
4 0 0

浅谈PHP中new self()和new static()的区别

本文介绍了PHP中new self()和new static()的区别,分享给大家,也给自己留个笔记。

1.new static()是在PHP5.3版本中引入的新特性。

2.无论是new static()还是new self(),都是new了一个新的对象。

3.这两个方法new出来的对象有什么区别呢,说白了就是new出来的到底是同一个类实例还是不同的类实例呢?

为了探究上面的问题,我们先上一段简单的代码:

class Father {

public function getNewFather() {
return new self();
}

public function getNewCaller() {
return new static();
}

}

$f = new Father();

print get_class($f-

© 版权声明

相关文章

暂无评论

暂无评论...