码迷,mamicode.com
首页 > 其他好文 > 详细

static::、self::、new self()、new static()

时间:2021-05-24 14:21:29      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:php   var_dump   protect   ted   ati   fun   code   The   protected   

static::、self::、new self()、new static()

<?php
class Father{
    protected static $name = "大头";
    public static function father_self(){
        echo self::$name."\n";
    }
     
    public static function father_static(){
        echo static::$name."\n";
    }
     
    public static function getInstance_self(){
        return new self();
    }
     
    public static function getInstance_static(){
        return new static();
    }
}
 
class Son extends Father{
    protected  static $name = "小头";
}
 
Son::father_self(); //大头
echo "<br>";
Son::father_static(); //小头
echo "<br>";
var_dump(Son::getInstance_self()); //Father
echo "<br>";
var_dump(Son::getInstance_static()); //Son

static::、self::、new self()、new static()

标签:php   var_dump   protect   ted   ati   fun   code   The   protected   

原文地址:https://www.cnblogs.com/jingdr/p/14779435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!