title: Load php core classes using custom autoloader
body: <p>I've been searching the database of questions on the forum, but can not get a solution that is oriented to my question.</p>
  
  <p>I come to you, because I doubt has arisen with an autoloader that I'm developing.</p>
  
  <p>The point is this, when I try to instantiate a class defined by me the autoloader works fine, but when I try to instantiate a class of the PHP core throws me the following error.</p>
  
  <p>For example, when I try to do this:</p>
  
  <pre><code>$conn = new PDO (...);
  </code></pre>
  
  <p>Then throws me the following error:</p>
  
  <pre><code>Fatal error: Class 'PDO' not found in ...
  </code></pre>
  
  <p>I've noticed that the autoloader is trying to load the class from which I have defined routes to my classes.</p>
  
  <p>My question is, how I can do to load a class of the PHP core if I'm using a custom autoloader?</p>
  
  <p>I hope you can guide me to solve this problem that I have been presented.</p>
  
  <p>In advance thank you very much.</p>
  
  <p>Excuse me for not placing the code of custom autoloader, I missed.</p>
  
  <p>The code is the same used in symfony but modified and simplified.</p>
  
  <pre><code>class ClassLoader {
  
  private $prefixes = array ();
  private $fallbackDirs = array ();
  private $useIncludePath = false;
  
  public function getPrefixes  () {
      return $this-&gt;prefixes;
  }
  
  public function getFallbackDirs  () {
      return $this-&gt;fallbackDirs;
  }
  
  public function addPrefixes ( array $prefixes ) {
      foreach  ( $prefixes as $prefix =&gt; $path )  {
          $this-&gt;addPrefix ( $prefix, $path );
      }
  }
  
  public function addPrefix ( $prefix, $paths ) {
      if  ( !$prefix ) {
          foreach ( ( array ) $paths as $path ) {
              $this-&gt;fallbackDirs [] = $path;
          }
          return;
      }
      if  ( isset ( $this-&gt;prefixes [ $prefix ] ) ) {
          $this-&gt;prefixes [ $prefix ] = array_merge ( $this-&gt;prefixes [ $prefix ], ( array ) $paths );
      } else {
          $this-&gt;prefixes [ $prefix ] = ( array ) $paths;
      }
  }
  
  public function setUseIncludePath ( $useIncludePath ) {
      $this-&gt;useIncludePath = $useIncludePath;
  }
  
  public function getUseIncludePath () {
      return $this-&gt;useIncludePath;
  }
  
  public function register ( $prepend = false ) {
      spl_autoload_register ( array ( $this, 'loadClass' ) , true, $prepend );
  }
  
  public function unregister () {
      spl_autoload_unregister ( array ( $this, 'loadClass' ) );
  }
  
  public function loadClass ( $class ) {
  
      if  ( $file = $this-&gt;findFile ( $class ) ) {
          require $file;
          return true;
      }
  }
  
  public function findFile ( $class ) {
      if ( '\\' == $class [ 0 ]  )  {
          $class = substr ( $class, 1 );
      }
      if  ( false !== $pos = strrpos ( $class, '\\' ) ) {
          // namespaced class name
          $classPath = str_replace ( '\\', DIRECTORY_SEPARATOR, substr ( $class, 0, $pos ) ) . DIRECTORY_SEPARATOR;
          $className = substr ( $class, $pos + 1 );
      } else {
          // PEAR-like class name
          $classPath = null;
          $className = $class;
      }
      $classPath .= str_replace ( '_', DIRECTORY_SEPARATOR, $className ) . '.php';
      foreach ( $this-&gt;prefixes as $prefix =&gt; $dirs ) {
          if ( 0 === strpos ( $class, $prefix ) ) {
              foreach ( $dirs as $dir ) {
                  if ( file_exists ( $dir . DIRECTORY_SEPARATOR . $classPath ) ) {
                      return $dir . DIRECTORY_SEPARATOR . $classPath;
                  }
              }
          }
      }
      foreach ( $this-&gt;fallbackDirs as $dir ) {
          if ( file_exists ( $dir . DIRECTORY_SEPARATOR . $classPath ) ) {
              return $dir . DIRECTORY_SEPARATOR . $classPath;
          }
      }
      if ( $this-&gt;useIncludePath &amp;&amp; $file = stream_resolve_include_path ( $classPath ) ) {
          return $file;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But if you want to see the original file is here</p>
  
  <p><a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/ClassLoader/ClassLoader.php" rel="nofollow">https://github.com/symfony/symfony/blob/master/src/Symfony/Component/ClassLoader/ClassLoader.php</a></p>