小白兔晒黑了

导航

 

1 普通静态绑定

 

<?php
class A
{
    public static function who()
    {
        echo __CLASS__.PHP_EOL;
    }
    public static function test()
    {
        self::who();
    }
}

class B extends A
{
    public static function who()
    {
        echo __CLASS__.PHP_EOL;
    }
}
B::test();
?>

输出:

 A

 

2 后期静态绑定

 

<?php
class A
{
    public static function who()
    {
        echo __CLASS__.PHP_EOL;
    }
    public static function test()
    {
        static::who();
    }
}

class B extends A
{
    public static function who()
    {
        echo __CLASS__.PHP_EOL;
    }
}
B::test();
?>

输出:

 B

posted on 2021-03-24 17:15  小白兔晒黑了  阅读(38)  评论(0编辑  收藏  举报