title: Importing PHP Namespace To Extend A Class In That Namespace
body: <p>This post is due to some difficulty I am having extending a class defined in a first namespace from a second namespace. Based on this post :</p>
  
  <p><a href="https://stackoverflow.com/questions/7121682/php-how-to-import-all-classes-from-another-namespace">PHP how to import all classes from another namespace</a></p>
  
  <p>I tried this :</p>
  
  <p>File NameSpace1 :</p>
  
  <pre><code>&lt;?php
  namespace FirstNS;
  
  class baseObject
  {
      public $baseVar = 1;
  
  public function baseFun() {}
  }
  
  ?&gt;
  </code></pre>
  
  <p>File NameSpace2 :</p>
  
  <pre><code>&lt;?php
  namespace SecondNS;
  
  use FirstNS;
  
  class extendedObject extends FirstNS\baseObject {
      public $extendedVar = 1;
  
      public function extendedFun() {
  
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>However <code>$this</code> in <code>extendedFun</code> can only access <code>$extendedVar</code> and <code>extendedFun</code>, not <code>$baseVar</code> and <code>baseFun</code>. I have also tried <code>use FirstNS as ClassFromFirstNS;</code> and <code>class extendedObject extends ClassFromFirstNS</code> however <code>$baseVar</code> and <code>baseFun</code> are still not accessible via <code>$this</code>. The information at <a href="http://www.php.net/manual/en/language.namespaces.rationale.php" rel="nofollow noreferrer">http://www.php.net/manual/en/language.namespaces.rationale.php</a>, <a href="http://www.php.net/manual/en/language.namespaces.definition.php" rel="nofollow noreferrer">http://www.php.net/manual/en/language.namespaces.definition.php</a> and <a href="http://www.php.net/manual/en/language.namespaces.importing.php" rel="nofollow noreferrer">http://www.php.net/manual/en/language.namespaces.importing.php</a> also did not seem to directly address this case.</p>