title: PHP Get parent class variables from child class constructed in the parent constructor
body: <p>With the following code snippet, why does <code>$this-&gt;foo</code> return <code>NULL</code> in the B child class constructor? From what I've read I was under the impression that a child class inherits all its parent variables and methods</p>
  
  <pre><code>$a = new A();
  
  class A {
      protected $foo;
  
      public function __construct() {
          $this-&gt;foo = "Hello World";
  
          $b = new B();
      }
  }
  
  class B extends A {
      public function __construct() {
          var_dump($this-&gt;foo);
      }
  }
  </code></pre>
  
  <p>The selected answer of <a href="https://stackoverflow.com/questions/6456939/php-accessing-parent-class-variable">this question</a> seems to suggest <code>$this-&gt;foo</code> should be accessible.</p>
  
  <p>Is it because B is being constructed from within its parent class? If that is the case, how can I access the variable in the child class?</p>