私は次の親子クラスを持っています。
class Parent_class {
protected static function method_one() {
echo "I am in Parent_class in method_one";
}
protected function execute() {
static::method_one();
}
public function start() {
$this->execute();
}
}
class Child_class extends Parent_class {
protected static function method_one() {
echo "I am in Child_class in method_one";
}
}
$obj = new Child_class();
$obj->start();
Result - it is calling Child class method.
php5.3 ではすでに予約済みのキーワードで静的レイト バインディングがサポートされているため、結果は期待どおりですstatic
。
static
しかし、問題は、親クラスへの書き込みアクセス権がないため、呼び出し中に使用できないためmethode_one
、遅延静的バインディングを実行していないことです。
オーバーライドメソッドにアクセスできる方法はありますか?
親クラスは定義済みのライブラリであり、変更できません。
解決策は、親クラスを変更するか、この考えを完全に削除することですが、他の代替案を提案できますか?