Bir ebeveyn statik bir yöntem içinde bir çocuğun sabit veya statik değişkenleri kullanmak için mümkün mü?

0 Cevap php

Aşağıda yapmaya çalışıyorum ne bir örnektir. Ebeveyn çocuğun değişkenlerin herhangi erişemez. Ben (statik veya sabitler) kullanmak ne tekniği önemli değil, ben sadece bu gibi işlevsellik çeşit gerekir.

class ParentClass
{
    public static function staticFunc()
    {
        //both of these will throw a (static|const) not defined error
        echo self::$myStatic;
        echo self::MY_CONSTANT;
    }
}

class ChildClass extends ParentClass
{
    const MY_CONSTANT = 1;
    public static $myStatic = 2;
}

ChildClass::staticFunc();

Ben bu berbat biliyorum, ama ben not using 5.3 duyuyorum. Eval içeren herhangi hacky çözüm bekliyoruz daha fazladır.

0 Cevap