PHP 中 new static 和 new self 的区别

来源:互联网 发布:软件测试行业现状 编辑:程序博客网 时间:2024/05/16 16:09
lass 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()); // Aecho get_class(B::get_static()); // Becho get_class(A::get_static()); // Anew self 那么获取的是当前代码段的这个类。 这个在class A 中写的方法 就算你在class B 中继承了,调用时返回的还是 class A 中的代码new static PHP 5.3新增的方法,有点 $this 的味道,调用对应的 class  就返回 对应 class 的方法。
阅读全文
0 0
原创粉丝点击