title: Accessing protected variables in PHP
body: <p>I'm trying to access protected variables in a second-child class extended from its parent, but every time I try to access them, they are NULL. </p>
  
  <p>What's weird to me is that I can access the parent's protected functions without a problem (eg. <code>$this-&gt;_submit</code> in the second child class.) I checked the parent class and the variable are set there, so I'm sure it's something dumb I am missing (still learning OOP). Maybe something to do with the constructor? But if I call <code>parent::__construct()</code> in the second child, it throws an error because the <code>config</code> details are missing?</p>
  
  <h2>Parent</h2>
  
  <pre><code>&lt;?php defined('SYSPATH') or die('No direct script access.');
  abstract class Rimage {
  
      protected $_config;
      protected $_service;
      protected $_client;
  
  public static function instance($config, $service)
  {
      return new Rimage_Client($config, $service);
  }
  
  public function __construct($config = array(), $service = NULL)
  {
      $this-&gt;_config  = $config;
      $this-&gt;_service = $service;
      $this-&gt;_client = new SoapClient('url');
  }
  
  }
  ?&gt;
  </code></pre>
  
  <h2>First Child</h2>
  
  <pre><code>&lt;?php defined('SYSPATH') or die('No direct script access.');
  
  class Rimage_Client extends Rimage {
  
      protected $_caller;
  
      public function __construct($config = array(), $service = NULL)
      {
          parent::__construct($config, $service);
          $this-&gt;_caller = Arr::get($config, 'caller', array());
      }
  
      public function get($id = NULL)
      {   
      return new Rimage_Job_Status($id);
      }
  
      protected function _submit($options, $request_class)
      {
          $job-&gt;request = $options;
  
          $response = $this-&gt;_client-&gt;$request_class($job); /** Client is undefined??**/
          return $response;   
      }
  
  } // End Rimage_Client
  ?&gt;
  </code></pre>
  
  <h2>Second Child</h2>
  
  <pre><code>&lt;?php defined('SYSPATH') or die('No direct script access.');
  class Rimage_Job_Status extends Rimage_Client {
  
      public function __construct($id) 
      {       
          return $this-&gt;_retrieve($id);
      }
  
      private function _retrieve($id = NULL)
      {
          $options-&gt;CallerId  = $this-&gt;_caller; /** $_caller is undefined??? **/
          $options-&gt;JobId     = $id;
  
          $response = $this-&gt;_submit($options, 'test');
          return $response-&gt;whatever;
      }
  
  } // End Rimage_Job_Status
  ?&gt;
  </code></pre>
  
  <p>Calling the code with <code>Rimage::instance($config,'job')-&gt;get('12345');</code></p>
  
  <h2>Edit:</h2>
  
  <p>The error I'm getting is that <code>$_client</code> is NULL in the child, but not in the parent... <code>$_caller</code> is NULL in the second child.</p>
  
  <p>Cheers and merry christmas!</p>