title: Redeclaring a class in PHP
body: <p>I need to include two files which contain classes with the same name. I was hopeful when I found this <a href="https://stackoverflow.com/questions/2658906/is-there-any-way-to-redeclare-a-class-safely-in-php?answertab=votes#tab-top">answer</a> using <code>namespaces</code>. but since both classes extend the same parent class I get an error saying MyNamespce/Parent not found.</p>
  <h2>MyClass.php</h2>
  <p>This is a shared resource that I cannot change.</p>
  <pre><code>// MyClass.php
  class MyClass extends Parent {
    const MY_CONST = 1;
    ...
  }
  </code></pre>
  <h2>MyNamespaceMyClass.php</h2>
  <p>I have some discretion on what to name things but I would like to keep changes minimal as this is a generated file.</p>
  <pre><code>// MyNamespaceMyClass.php
  namespace MyNamespace;
  class MyClass extends Parent {
     const MY_CONST = 2;
     ...
  }
  </code></pre>
  <h2>example.php</h2>
  <p>Finally the code where I use classes:</p>
  <pre><code>// example.php
  require_once 'MyClass.php';
  require_once 'MyNamespaceMyClass.php';
  
  /**
   * Converts My Class into the newer version.
   *
   * @param MyClass $my_class.
   * @return MyNamespace\MyClass
   */
   function convert_myclass(MyClass $my_class) {
     $new_my_class = new MyNamespace\MyClass();
     ...
     return $new_my_class;
   }
  </code></pre>
  <p>The problem is that I get <code>Fatal error: Class 'MyNamespace\MyClass' not found in MyNamespaceMyClass.php</code>. Is there a way to use namespaces to import identically named classes, which also extend from the same class?</p>