title: PHP Composer PSR-4 Autoloading And Sub-Namespaces, Class Not Found
body: <p>This question is independent but I did ask a similar question before:-</p>
  
  <p><a href="https://stackoverflow.com/questions/33289135/composer-gives-error-class-not-found">Composer Gives Error, &quot;Class Not Found&quot;</a></p>
  
  <p>The problem was solved but I failed to explain the nesting issue. I thought it will be more appropriate to make a new question.</p>
  
  <p>I searched a lot but I can't make the nesting namespaces to work with psr-4 autoloading.</p>
  
  <p>Directory Structure:-</p>
  
  <pre><code>│   composer.json
  │   run.php
  │
  ├───src
  │   ├───one
  │   │       parentclass.php
  │   │
  │   └───two
  │           childclass.php
  │
  └───vendor
      │   autoload.php
      │
      └───composer
              autoload_classmap.php
              autoload_namespaces.php
              autoload_psr4.php
              autoload_real.php
              ClassLoader.php
              installed.json
              LICENSE
  </code></pre>
  
  <p>parentclass.php:-</p>
  
  <pre><code>&lt;?php
  
  namespace myns\one;
  
  abstract class parentclass
  {
      abstract public function abc();
  }
  </code></pre>
  
  <p>childclass.php:-</p>
  
  <p>
  
  <pre><code>namespace myns\two;
  
  namespace myns\one;
  
  use myns\one\parentclass as parentclass;
  
  class childclass extends parentclass
  {
      public function abc()
      {
          echo 'hello world';
      }
  }
  </code></pre>
  
  <p>composer.json:-</p>
  
  <pre><code>{
      "name": "myvendor/mypackage",
      "description": "nothing",
      "authors": [
          {
              "name": "Omar Tariq",
              "email": "XXXXX@gmail.com"
          }
      ],
      "require": {},
      "autoload": {
          "psr-4": {
              "myns\\": "src/",
              "myns\\one\\": "src/one/",
              "myns\\two\\": "src/two/"
          }
      }
  }
  </code></pre>
  
  <p>run.php:-</p>
  
  <pre><code>&lt;?php
  
  require_once __DIR__ . '/vendor/autoload.php';
  
  use myns\two\childclass as childclass;
  
  $childclass = new childclass();
  $childclass-&gt;abc();
  </code></pre>
  
  <p>When I run <code>php run.php</code>. It gives error:-</p>
  
  <pre><code>Fatal error: Class 'myns\two\childclass' not found in C:\wamp\...\run.php on line 7
  </code></pre>