title: PHP namespace scope for a child class' method?
body: <p>I ran into an issue with parent/child classes in different namespaces that I'm wondering if it's my improper use, or if this is a quirk of PHP namespaces:</p>
  
  <pre><code>&lt;?php
  namespace myVendorName;
  class MyParentClass {
    protected $args = array();
    function factory($class) {
      return new $class($this-&gt;args);
    }
  }
  ?&gt;
  
  &lt;?php
  namespace myVendorName\subPackage;
  class foo {
  }
  class bar extends \myVendorName\MyParentClass {
    function myFunc() {
      var_dump(new foo()); // Works (we're in the same namespace)
      var_dump($this-&gt;factory('foo')); // Doesn't work (no such class as myVendorName\foo)
      var_dump($this-&gt;factory('subPackage\foo')); // Works
    }
  }
  ?&gt;
  </code></pre>
  
  <p>The above code doesn't work as I'd expect. In the <code>\myVendorName\subPackage\bar-&gt;myFunc()</code> method, I'd like to get a <code>\myVendorName\subPackage\foo</code> class. If I just create it there, I can create it by only its class name since the namespace is the same. However, those classes in reality are more complex, and there's a factory method to create them. The factory method is universal, and is defined in the root vendor namespace. And the <code>bar</code> class doesn't overwrite that factory method; it simply inherits it. However, when referring to a class object by name, it seems to still operate in the parent's namespace, rather than having the method truly get inherited by the child and operate in the child's namespace.</p>
  
  <p>Is there a way for a parent class method that's going to be inherited directly to use the child's namespace, or at least peek at what it is? Or does each of my child classes have to overwrite the factory method to fix the namespace, and call the parent method within themselves?</p>