title: PHP OOP inheritance issue. Can't access parent variable from child class
body: <p>I have a class like this:</p>
  
  <pre><code>class A {
  
   public $var = "";
  
   function __construct() {
  
    $this-&gt;var = "value";
  
   }
  
  }
  </code></pre>
  
  <p>And a child class like this:</p>
  
  <pre><code>class B extends A {
  
   function __construct() {
  
    // Is this correct?
    parent::__construct();
  
   }
  
   function my_function() {
  
    // Or this?
    // $options is an instantiation of A.
    global $options;
  
    echo $this-&gt;var;
  
   }
  
  }
  </code></pre>
  
  <p>The problem I was having is that when I called the my_function() method, the value of var was empty. After reading on php.net for a while I found out that when a child class has its own constructor, the parent constructor is overridden which is why my variable was empty. My question is if the way I'm calling parent::__construct() is the right solution or if I should just globalize the instantiated object that I created in my script? I've done a lot of reading in comments on PHP.net and other places and I couldn't find anything concise.</p>