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()); // A echo get_class(B::get_static()); // B echo get_class(A::get_static()); // A new self 那么获取的是当前代码段的这个类。 这个在class A 中写的方法 就算你在class B 中继承了,调用时返回的还是 class A 中的代码 new static PHP 5.3新增的方法,有点 $this 的味道,调用对应的 class 就返回 对应 class 的方法。
PHP 中 new static 和 new self 的区别
最新推荐文章于 2024-05-16 18:51:41 发布