美文网首页
php new static 和 new self的区别

php new static 和 new self的区别

作者: _李丹丹_ | 来源:发表于2018-10-22 14:52 被阅读0次
    <?php
    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_self()); // A
    echo get_class(A::get_static()); // A
    

    相关文章

      网友评论

          本文标题:php new static 和 new self的区别

          本文链接:https://www.haomeiwen.com/subject/jhrgzftx.html