title: Composer packages, autoloading non-class based files
body: <p>When I was digging into the source of a Composer package <a href="https://github.com/CrunchPHP/RegularExpression" rel="noreferrer">on github</a> I noticed that there were <em>php files that matched namespace names</em> but were preceded with an underscore. Puzzled I pulled the package down (via Composer) and noticed that the class loader that Composer generates <code>require</code>d these underscored files explicitly, not autoloading as I'd expected.</p>
  <p>For instance, in the <code>crunch/regular-expression</code> package there is a namespace called
  <code>Crunch\RegularExpression</code>:</p>
  <pre><code>-- src
  ---- Crunch
  ------- RegularExpression       &lt;-- folder containing classes
  ------- _RegularExpression.php  &lt;-- file namespace to Crunch/RegularExpression
                                      containing functions and constants 
                                      (instead of a class)
  </code></pre>
  <p>Initially I thought these underscored files were a feature of PSR-0 that I had missed, but then I looked at the Composer generated <code>autoload_real.php</code> and saw that <code>_RegularExpression.php</code> (amongst others) was being required explicitly:</p>
  <pre><code>…
  $loader-&gt;register(true);
  
  require $baseDir . '/src/Crunch/_RegularExpression.php';
  require $baseDir . '/src/Crunch/RegularExpression/_Modifier.php';
  require $baseDir . '/src/Crunch/RegularExpression/Pattern/_Modifier.php';
  require $baseDir . '/src/Crunch/RegularExpression/Pattern/_Assertion.php';
  
  return $loader;
  …
  </code></pre>
  <p>Haven't been able to find any meaningful documentation about this feature of Composer. Is it a good &quot;standard&quot; for exporting non-class based namespaced dependencies, like functions and constants?</p>
  <h2>Update</h2>
  <p>My question turned out to be a slight misnomer. The selected answer lead me to discover that non-class based assets can be explicitly declared for loading in <code>composer.json</code>:</p>
  <pre><code>&quot;autoload&quot;: {
      &quot;psr-0&quot;: { &quot;Crunch\\RegularExpression&quot;: &quot;src&quot; },
      &quot;files&quot;: [
          &quot;src/Crunch/_RegularExpression.php&quot;,
          &quot;src/Crunch/RegularExpression/_Modifier.php&quot;,
          &quot;src/Crunch/RegularExpression/Pattern/_Modifier.php&quot;,
          &quot;src/Crunch/RegularExpression/Pattern/_Assertion.php&quot;
      ]
  }
  </code></pre>
  <p>The underscores on the files were a convention used to delineate them from class definitions and have no special purposes in autoloading.</p>