title: How does composer know which classes are used?
body: <p>I was wondering how Composer knows which <em><strong>classes</strong></em> are used in the scripts that will be executed. Does PHP provide a hooking mechanism with a callback? I'm guessing it's not inspecting the code since the following code works (provided the PHP Redis extension is installed, Redis is running  on localhost with the auth token provided and the class_name key is set to the string <code>'App\Examples\B'</code>):</p>
  <strong>/app/Examples/A.php</strong>
  <pre class="lang-php prettyprint-override"><code>&lt;?php namespace App\Examples;
  
  class A
  {
      public function __construct()
      {
          echo &quot;Constructing A!\n&quot;;
      }
  }
  </code></pre>
  <strong>/app/Examples/B.php</strong>
  <pre class="lang-php prettyprint-override"><code>&lt;?php namespace App\Examples;
  
  class B
  {
      public function __construct()
      {
          echo &quot;Constructing B!\n&quot;;
      }
  }
  </code></pre>
  <strong>/app/main.php</strong>
  <pre class="lang-php prettyprint-override"><code>&lt;?php namespace App;
  
  use App\Examples\A;
  
  include __DIR__ . '/../vendor/autoload.php';
  
  $r = new \Redis;
  $r-&gt;connect('localhost');
  $r-&gt;auth('GJuqgx[0h-OtO94X7W[9');
  
  // App\Examples\B
  $class_name = $r-&gt;get('class_name');
  
  $a = new A;
  $b = new $class_name;
  </code></pre>
  <p>Running this from the command line produces the expected output:</p>
  <pre><code>$ php app/main.php
  Constructing A!
  Constructing B!
  </code></pre>
  <p>How does composer know to even look for <code>App\Examples\B</code>?</p>
  <p>I'd like to emphasize that I am <strong>NOT</strong> asking how composer knows <strong>where</strong> to find <code>App\Examples\B</code>, rather, I am asking <strong>how</strong> it knows that it will need to find <code>App\Examples\B</code> in the first place.</p>