title: PHP: cannot declare class because the name is already in use
body: <p>I have 5 scripts: </p>
  
  <ol>
  <li><code>database.php</code></li>
  <li><code>parent.php</code></li>
  <li><code>child1.php</code></li>
  <li><code>child2.php</code></li>
  <li><code>somescript.php</code></li>
  </ol>
  
  <p><code>parent.php</code> class looks like this:</p>
  
  <pre><code>include 'database.php';
  
  class Parent {
      public $db;
      function __construct() {
          $this-&gt;db = new Database();
      }
  }
  </code></pre>
  
  <p>The <code>child1.php</code> and <code>child2.php</code> classes looks like this:</p>
  
  <pre><code>include 'parent.php';
  
  class Child1 extends Parent {
      function __construct() {
          parent::__construct();
      }
  
      function useDb() {
          $this-&gt;db-&gt;some_db_operation();
      }
  }
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>When I try to include both child1 and child2 in somescript.php, it returns the following error:</p>
  
  <blockquote>
    <p>cannot declare class Database because the name is already in use in
    database.php on line 4 <em>(this is the line which contains words 'class Database')</em></p>
  </blockquote>
  
  <p>But if I include only a single file (child1 or child2), it works great.</p>
  
  <p>How do I correct that?</p>