title: Get child class namespace from superclass in PHP
body: <p>Assuming I have the following classes in different files:</p>
  
  <pre><code>&lt;?php
      namespace MyNS;
  
      class superclass {
  
          public function getNamespace(){
              return __NAMESPACE__;
          }
      }
  ?&gt;
  
  &lt;?php
      namespace MyNS\SubNS;
  
      class childclass extends superclass { }
  ?&gt;
  </code></pre>
  
  <p>If I instantiate "childclass" and call getNamespace() it returns "MyNS".</p>
  
  <p>Is there any way to get the current namespace from the child class without redeclaring the method?</p>
  
  <p>I've resorted to creating a static $namespace variable in each class and referencing it using <code>super::$namespace</code> but that just doesn't feel very elegant.</p>