Edit report at https://bugs.php.net/bug.php?id=62320&edit=1

 ID:                 62320
 Comment by:         dagguh at gmail dot com
 Reported by:        techlivezheng at gmail dot com
 Summary:            Abstract static property?
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        5.4.3
 Block user comment: N
 Private report:     N

 New Comment:

Late Static Binding is a failed concept and should be avoided in all cases.
There is no such thing as static inheritance. Static members of a class belong 
to 
this class and this class only.

Just use the regular instance methods and regular inheritance.
Your code will be more testable, extensible and modular.

Please close this issue as "won't fix".


Previous Comments:
------------------------------------------------------------------------
[2012-06-14 07:04:45] techlivezheng at gmail dot com

Description:
------------
As we have "late static bindings" now, would it be reasonable to have a 
"abstract static property"?

See the bellow example.

abstract class A {
    //If this could be declared as abstract to make 
    //the subclass have to redeclare it in order to
    //have it own $mTest to use.
    //If $mTest is not declared in one subclass, it would
    //change the $mTest of A which is shared by many 
    //subclasses, some unexpected things would happen.
    //The design is to make each subclass have its own
    //$mTest to use and it has to be existed.
    //$mTest in A is just for a skeleton purpose, even should
    //not be assigned a value.
    static $mTest;

    static function setTest($value) {
        static::$mTest = $value;
    }

    static function DumpTest () {
        echo 'static:' . static::$mTest . "\n";
        echo 'A-self:' . self::$mTest . "\n";
    }
}

class B extends A {
    static function DumpTest () {
        parent::DumpTest();
        echo 'B-self:' . self::$mTest . "\n";
        echo 'B-parent:' . parent::$mTest . "\n";
    }
}

class C extends A {
    static $mTest;
    static function DumpTest () {
        parent::DumpTest();
        echo 'C-self:' . self::$mTest . "\n";
        echo 'C-parent:' . parent::$mTest . "\n";
    }
}

class D extends C {
    static $mTest;
    static function DumpTest () {
        parent::DumpTest();
        echo 'D-self:' . self::$mTest . "\n";
        echo 'D-parent:' . parent::$mTest . "\n";
    }
}

B::setTest('test1');//This will change the $mStorages of class A
B::DumpTest();
//static:test1
//A-self:test1
//B-self:test1
//B-parent:test1
C::setTest('test2');
C::DumpTest();
//static:test2
//A-self:test1
//C-self:test2
//C-parent:test1
D::setTest('test3');
D::DumpTest();
static:test3
//A-self:test1
//C-self:test2
//C-parent:test1
//D-self:test3
//D-parent:test2



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62320&edit=1

Reply via email to