首页 > Web开发 > 详细

php相关知识总结

时间:2021-03-14 14:05:16      阅读:39      评论:0      收藏:0      [点我收藏+]
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时效果一样

php相关知识总结

原文:https://www.cnblogs.com/zhiguopingtianxia/p/14531693.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!