Is it possible for a parent to use a child's constant or static variables from inside a static metho

Posted by ryeguy on Stack Overflow See other posts from Stack Overflow or by ryeguy
Published on 2010-06-07T13:53:58Z Indexed on 2010/06/07 14:02 UTC
Read the original article Hit count: 145

Filed under:
|

Below is an example of what I'm trying to do. The parent can't access any of the child's variables. It doesn't matter what technique I use (static or constants), I just need some kind of functionality like this.

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();

© Stack Overflow or respective owner

Related posts about php

Related posts about oop