title: Using classes outside of the current directory in PHP
body: <p>I have two folders in my directory:</p>
  
  <ul>
  <li>Plugins</li>
  <li>Classes</li>
  </ul>
  
  <p>The Plugins folder contains two files: Sample.php and Plugins.php.</p>
  
  <p>Sample.php is just a class with one function that extends the Plugins class. The Plugins class tries to create a new instance of the base class which is located in the Classes folder.</p>
  
  <p>Plugins/Sample.php:</p>
  
  <pre><code>class Sample extends Plugins {
  
      public $eggs;
      public $pounds;
  
      public function __construct() {
          $this-&gt;eggs   = "100";
          $this-&gt;pounds = "10";
      }
  
      public function OnCall() {
          echo "{$this-&gt;eggs} eggs cost {$this-&gt;pounds} pounds, {$this-&gt;name}!";
      }
  }
  </code></pre>
  
  <p>Plugins/Plugins.php:</p>
  
  <pre><code>class Plugins {
  
      public $name;
  
      public function __construct() {
          include '../Classes/Base.php';
          $base = new Base();
          $this-&gt;name = $base-&gt;name;
      }
  }
  </code></pre>
  
  <p>Classes/Base.php:</p>
  
  <pre><code>class Base {
  
      public $name = "Will";
  
      public function Say() {
          echo $this-&gt;name;
      }
  
  }
  </code></pre>
  
  <p>Index.php includes everything in the Plugins folder and is supposed to execute OnCall(). It is giving the following error messages:</p>
  
  <blockquote>
    <p>Warning: include(../Classes/Base.php) [function.include]: failed to
    open stream: No such file or directory in
    /Applications/XAMPP/xamppfiles/htdocs/Plugins/Plugins/Plugins.php on
    line 6</p>
    
    <p>Warning: include() [function.include]: Failed opening
    '../Classes/Base.php' for inclusion
    (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear')
    in /Applications/XAMPP/xamppfiles/htdocs/Plugins/Plugins/Plugins.php
    on line 6</p>
    
    <p>Fatal error: Class 'Base' not found in
    /Applications/XAMPP/xamppfiles/htdocs/Plugins/Plugins/Plugins.php on
    line 7</p>
  </blockquote>
  
  <p>Index.php (if it helps):</p>
  
  <pre><code>foreach(glob('Plugins/*.php') as $file) {
      require_once $file;
      $class = basename($file, '.php');
      if(class_exists($class)) {
          $obj = new $class;
          $obj-&gt;OnCall();
      }
  }
  </code></pre>
  
  <p>What I need to do is use the Base class in classes outside of the Classes folder. How can I do so?</p>