辨析new self(); new static();

xiaoxiao2021-02-28  82

辨析

new self(); new static();

参见

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

static是延迟绑定,就是说绑定在最后一次用的类上;而self在哪里面写就是指向哪个类的

转载请注明原文地址: https://www.6miu.com/read-97019.html

最新回复(0)