title: Include and namespace in php
body: <p>I have created this factory class:</p>
  
  <pre><code>namespace ValidatorFactory;
  
  foreach (glob("Types/*.php") as $filename)
  {
      include $filename;
  }
  
  class ValidatorFactory
  {
      public static function getValidator($betTypeId)
      {
          switch ($betTypeId)
          {
              case 1:
                  return new B();
                  break;
  
              default:
                  return null;
          }
      }
  }
  </code></pre>
  
  <p>Here is my A abstract class definition:</p>
  
  <pre><code>abstract class A
  {
      abstract function validateSchema($schema);
  }
  </code></pre>
  
  <p>Here is my B class definition:</p>
  
  <pre><code>class B extends A
  {
      function validateSchema($schema)
      {
          return true;
      }
  }
  </code></pre>
  
  <p>Now I want to use the factory class in some other file in my project, here is how I am doing it:</p>
  
  <pre><code>$obj = ValidatorFactory::getValidator($someId);
  </code></pre>
  
  <p>I am using Laravel and via composer (and <a href="https://www.youtube.com/watch?v=e2MLepOlT9Q&amp;list=UUpOIUW62tnJTtpWFABxWZ8g" rel="nofollow">this tutorial</a>) I tried to load the <code>ValidatorFactory</code> class like built in classes of laravel. Here is what I have added to the composer file:  </p>
  
  <pre><code>"autoload": {
      "classmap": [
          ...
      ],
      "psr-0": {
          "ValidatorFactory": "app/"
      }
  },
  </code></pre>
  
  <p>I have run <code>composer update</code>.  </p>
  
  <p>My problem is that my ValidatorFactory is not loaded because I am getting this error:</p>
  
  <pre><code>Class 'ValidatorFactory' not found
  </code></pre>
  
  <p>If I will add the namespace like this: </p>
  
  <pre><code>$obj = ValidatorFactory\ValidatorFactory::getValidator($someId);
  </code></pre>
  
  <p>I am getting other error, here it is: </p>
  
  <pre><code>Class 'ValidatorFactory\B' not found
  </code></pre>
  
  <p>So there are 2 problems, first related to larave/composer autoload (of the namespace). The second is related to includes and inheritance (as I suspect) in php.</p>
  
  <p>How can I solve this two issues? Thanks!</p>
  
  <p><strong>Update:</strong>
  As suggested in the answer, I have added the same namespace for all 3 involved classes A, B and the factory. No class including any other class.</p>
  
  <p>In the class which calls the factory's <code>getValidator</code> function I am doing it like this:</p>
  
  <pre><code>$obj = ValidatorFactory\ValidatorFactory::getValidator($someId);
  </code></pre>
  
  <p>Still getting the error which says class B is unknown :(</p>
  
  <p>Here is how the updated class B looks like:</p>
  
  <pre><code>namespace ValidatorFactory;
  class B extends A
  {
      function validateSchema($schema)
      {
          return true;
      }
  }
  </code></pre>
  
  <p>The file structure looks like this: factory file located in <code>app/dir1/</code> , Class A and B located in <code>app/dir1/dir2/</code></p>