title: PHP Private variable access from child
body: <p>so I'm trying to work out an issue I'm having in designing PHP classes. I've created a base class, and assigned private variables. I have child classes extending this base class, which make reference and changes to these private variables through functions of the base class. Here's an example, keep in mind I'm still confused about the difference between <code>private</code> and <code>protected</code> methods/variables (let me know if I'm doing it wrong!):</p>
  
  <p>base.class.php</p>
  
  <pre><code>&lt;?php
  class Base {
      private $test;
      public function __construct(){
          require('sub.class.php');
          $sub = new Sub;
          echo($this-&gt;getTest());
      }
      public function getTest(){
          return $this-&gt;test;
      }
      protected function setTest($value){
          $this-&gt;test = $value;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>sub.class.php</p>
  
  <pre><code>&lt;?php
  class Sub extends Base {
      public function __construct(){
          parent::setTest('hello!');
      }
  }
  ?&gt;
  </code></pre>
  
  <p>So I'd expect the result to be <code>hello!</code> printed on the screen - instead there is nothing. There could be a fundamental misunderstanding of classes on my part, or maybe I'm just doing something wrong. Any guidance is very much appreciated! Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>Thank you to everyone who contributed an answer - I think, despite the excellent solutions, that child classes are actually not what I need - it seems delegate classes may be more useful at this point, as I don't really need to reference the Base functions from within the other classes.</p>