title: PHP: Accessing protected var from child class
body: <p>I'm learning PHP and I'm stuck i the following code:</p>
  
  <pre><code>&lt;?php
  
  class dogtag {
  
      protected $Words;
  
  }
  
  class dog {
  
      protected $Name;
      protected $DogTag;
  
      protected function bark() {
          print "Woof!\n";
      }
  
  }
  
  class poodle extends dog {
  
      public function bark() {
          print "Yip!\n";
      }
  
  }
  
  $poppy = new poodle;
  $poppy-&gt;Name = "Poppy";
  $poppy-&gt;DogTag = new dogtag;
  $poppy-&gt;DogTag-&gt;Words = "My name is
  Poppy. If you find me, please call 555-1234";
  
  var_dump($poppy);
  
  ?&gt;
  </code></pre>
  
  <p>This is what I got:</p>
  
  <pre><code>PHP Fatal error:  Uncaught Error: Cannot access protected property poodle::$Name
  </code></pre>
  
  <p>This looks strange to me as I should access protected vars and functions from child classes.</p>
  
  <p>Could please someone explain where I'm wrong?</p>
  
  <p>Many thanks.</p>