title: PSR4 Composer Autoload Fatal error: Trait not found
body: <p>I'm attempting to implement this error handling class into my php website <a href="https://github.com/niteshapte/advanced-error-exception-handler-logger-php" rel="nofollow noreferrer">https://github.com/niteshapte/advanced-error-exception-handler-logger-php</a> but I keep getting the error </p>
  
  <blockquote>
    <p>PHP Fatal error: Trait 'SingletonTrait' not found in www.example.com/application/core/ErrorExceptionHandler.php on line 37.</p>
  </blockquote>
  
  <p>Line 37 is the second <code>use SingletonTrait;</code> statement.</p>
  
  <p>I've only just wrapped my head around namespaces and then traits come along!</p>
  
  <p>My code is below....I've stripped a lot of the code for brevity, but the full code can be viewed at the github URL above.</p>
  
  <p>Can you spot what I'm doing wrong?</p>
  
  <p>Source for www.example.com/application/core/ErrorExceptionHandler.php</p>
  
  <pre><code>&lt;?php
  namespace Utilities;
  use SingletonTrait;
  
  if(!defined('DIRECT_ACCESS')) {
      die("Direct access is forbidden.");
  }
  
  class ErrorExceptionHandler implements IUtilities {
  
      // Singleton instance - the line below generates the error
      use SingletonTrait;
  ....
  }
  </code></pre>
  
  <p>Source for www.example.com/application/core/SingletonTrait.php</p>
  
  <pre><code>&lt;?php
  namespace Utilities;
  use FrameworkException;
  
  if(!defined('DIRECT_ACCESS')) {
      die("Direct access is forbidden.");
  }
  
  trait SingletonTrait {
  .....
  }
  </code></pre>
  
  <p>Source for www.example.com/application/core/FrameworkException.php</p>
  
  <pre><code>&lt;?php
  namespace Utilities;
  
  if(!defined('DIRECT_ACCESS')) {
      die("Direct access is forbidden.");
  }
  
  class FrameworkException extends \Exception { }
  </code></pre>
  
  <p>Source for www.example.com/application/core/IUtilities.php</p>
  
  <pre><code>&lt;?php
  namespace Utilities;
  
  if(!defined('DIRECT_ACCESS')) {
      die("Direct access is forbidden.");
  }
  
  interface IUtilities { }
  </code></pre>
  
  <p>Source for www.example.com/index.php</p>
  
  <pre><code>&lt;?php
  require '../vendor/autoload.php';
  
  use Utilities\ErrorExceptionHandler;
  define("DIRECT_ACCESS", TRUE);
  ErrorExceptionHandler::getInstance();
  </code></pre>
  
  <p>This is what I have in my www.example.com/composer.json</p>
  
  <pre><code>"autoload": {
      "psr-4": { "": ["application/core/", "application/model/"],
                 "Utilities\\": "application/core/",
                 "SingletonTrait\\": "application/core/",
                 "FrameworkException\\": "application/core/"
      }
  }
  </code></pre>
  
  <p>Once I've uploaded that to my server, I issue <code>composer dump-autoload</code> at my PuTTY command line.</p>
  
  <p>This generates the following source at www.example.com/vendor/composer/autoload_psr4.php</p>
  
  <pre><code>&lt;?php
  
  // autoload_psr4.php @generated by Composer
  
  $vendorDir = dirname(dirname(__FILE__));
  $baseDir = dirname($vendorDir);
  
  return array(
      'phpDocumentor\\Reflection\\' =&gt; array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/type-resolver/src', $vendorDir . '/phpdocumentor/reflection-docblock/src'),
      'Webmozart\\Assert\\' =&gt; array($vendorDir . '/webmozart/assert/src'),
      'Utilities\\' =&gt; array($baseDir . '/application/core'),
      'Symfony\\Component\\Yaml\\' =&gt; array($vendorDir . '/symfony/yaml'),
      'SingletonTrait\\' =&gt; array($baseDir . '/application/core'),
      'Gregwar\\Captcha\\' =&gt; array($vendorDir . '/gregwar/captcha'),
      'FrameworkException\\' =&gt; array($baseDir . '/application/core'),
      'Doctrine\\Instantiator\\' =&gt; array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
      'DeepCopy\\' =&gt; array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
      '' =&gt; array($baseDir . '/application/core', $baseDir . '/application/model'),
  );
  </code></pre>
  
  <p>I've read as much as I can about autoloading traits but I haven't found an answer.</p>
  
  <p>My command line PHP version is 5.6.30.</p>