title: Setting protected variable value in child class and accessing value in parent
body: <p>I'm not sure if this is even possible but here goes. I want to set the value of a protected variable from within a child class and then access that value from the parent class. This is what I have tried:</p>
  
  <pre><code>class A {
      protected $a;
  
      public function __construct() {
          new B;
  
          echo "Parent Value: {$this-&gt;a}";
      }
  
      protected function setter($value) {
          $this-&gt;a = $value;
      }
  }
  
  class B extends A {
      public function __construct() {
          $this-&gt;setter('set value');
  
          echo "Child Value: {$this-&gt;a}&lt;br /&gt;";
      }
  }
  
  
  new A;
  </code></pre>
  
  <p>I'm expecting the output for the above code to be:</p>
  
  <pre><code>Child Value: set value
  Parent Value: set value
  </code></pre>
  
  <p>However I get the following instead:</p>
  
  <pre><code>Child Value: set value
  Parent Value:
  </code></pre>
  
  <p>Is it possible to set the value of a protected variable from within a child class and then access that value in the parent class? If not how would I accomplish this?</p>