0

I'm new to the extends classes and am having a little trouble with is issue. I'm trying to get a variable initiated by use of a different function then the construct. It should make more sense if you look below.

class A
{
    private static $_var;

    function __construct($EGGS)
    {
        $this->_var=$EGGS
    }

    private static function _ini()
    {
        $this->_var="hard coded value";
    }
}

class B extends A
{
     //How do I initiate private static $_var with the _ini() instead of using
     //the __construct here in good old class B?
}

$a = new A("foo");//works just fine
$b = new B;
hogarth45
  • 3,387
  • 1
  • 22
  • 27
  • 2
    First of all fix a bug - in static context use self instead of $this: http://stackoverflow.com/questions/151969/when-to-use-self-vs-this – Rafi Oct 17 '13 at 07:10
  • 1
    why you declare function private when you have to call it outside of Class, use public static function and call A::_ini() ...simple? – Sumit Gupta Oct 17 '13 at 07:14
  • 2
    You do realise, that each time you instantiate an object of class A the `static $_var` gets overwritten, right? Is that really what you want? Also, have you tried to instantiate your class A as it is, so you could get the error `Accessing static property A::$_var as non static` ? – Havelock Oct 17 '13 at 07:15
  • where would I call A::_ini() at? Inside B, when declaring a new B? – hogarth45 Oct 17 '13 at 07:25

0 Answers0