7

子クラスの関数を必要とせずにこれを達成しようとしています...これは可能ですか?そうではないと感じていますが、本当に確認したいのですが...

<?php
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // Here comes Late Static Bindings
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

B::test(); //returns B
?>
4

1 に答える 1

14

get_called_class()の代わりに使用してください__CLASS__。関数が遅延バインディングを介してクラスを解決するため、staticに置き換えることもできます。self

class A {
    public static function who() {
        echo get_called_class();
    }
    public static function test() {
        self::who();
    }
}

class B extends A {}

B::test();
于 2012-03-06T04:42:15.190 に答える