php相關知識總結
class Father{ public static function getStatic(){ return new static(); } public static function getSelf(){ return new self(); } } trait GrandFather{ public static function getStatic(){ return new static(); } public static function getSelf(){ return new self(); } } class Son1{ use GrandFather; } class Son2 extends Father { } $o1 = Son1::getStatic(); $o2 = Son2::getStatic();
new static和new self的表現,self時是new父類自己,static是代表當前子類且在使用extend和trait時效果一樣

浙公網安備 33010602011771號