title: Symfony ClassLoader or PHP autoload ca't find class after programmatic src code changes
body: <p>This is an app that's intended to generate entities, allowing the end user to define the fields, and it worked like charm, until Sf 2.3 and PHP version something(don't recall the version that was running) on a debian 7. But now it's on a FreeBSD with PHP 5.4.28 and SF 2.4</p>
  
  <p>It can create an entity from scratch or recreate and overwrite it with changes.. but all of a suden, the autoloader stopped (re-)loading the class after it's created. It wont be until next postback, that it actually sees the class, obviously if I don't create it again (e.g. commenting code). </p>
  
  <p>So, The question is <strong>How can I force autoload of a class whose code had been written and saved to the class' php file during the request handling..?</strong></p>
  
  <p>The following code gives class not found.</p>
  
  <pre><code>/**
   * Handles creation of the Doctrine Entity that will represent de Document being 
   * created.
   * 
   * @param DocumentType $docDefinition The Document definition
   * 
   * @return string Genedated Document's class shortcut notation.
   * 
   * @throws \Exception if {@link $this-&gt;doctrineGenEntityCmd}-&gt;run() fails or throws
   */
  protected function createDocumentEntity(DocumentType $docDefinition)
  {
      $this-&gt;log-&gt;info("Creating Document entity");
      try {
          list($exitCode, $out) = 
              $this-&gt;runCommand('generate:doctrine:entity', $this-&gt;generateEntityCmd, $docDefinition);
      } catch (\Exception $exc) {
          throw new \Exception(
              sprintf("Can't create Document due to following: \n %s", $exc-&gt;getTraceAsString()),
              null,
              $exc    
          );
      }
      if (0 != $exitCode) {
          throw new \Exception(
              sprintf("Can't create Document due to following: \n %s", $out-&gt;getErrorOutput())
          );
      }
  
      $justToAutoload = $this-&gt;tryInstantiate($docDefinition);
      $this-&gt;log-&gt;info($justToAutoload);
      return InputHandler\InputHandler::getClassShortcutNotation($docDefinition);
  }
  </code></pre>
  
  <p>Inside the debugging fn <code>tryInstantiate()</code> I tried several things, unregistering autoloaders, re-including composer's (app/autoload.php) </p>
  
  <pre><code>protected function tryInstantiate(DocumentType $docDefinition)
  {
      $fqcn = "\\" . $this-&gt;getDocumentFqcn($docDefinition);
      $log = $this-&gt;log;
      $functions = spl_autoload_functions();
      foreach($functions as $function) {
          spl_autoload_unregister($function);
      }
  
      $newLoader = include $this-&gt;kernel-&gt;getRootDir() . '/autoload.php';
      $newLoader-&gt;register(true);
  
      $log-&gt;info('tryInstantiate');
  //        spl_autoload_register(function ($className) use ($fqcn, $log) {
  //            if ($className == $fqcn) {
  //                $log-&gt;info("Loading: " . $className);
  //                $baseDir = $this-&gt;kernel-&gt;getRootDir() . '/../src';
  //                $classFile = $baseDir . str_replace('\\', DIRECTORY_SEPARATOR , $fqcn) . '.php';
  //                include $classFile;
  //            }
  //        }, true, true);
      //$fqcn = str_replace('\\', '\', $fqcn);
      return $test = new  \DocDigital\Bundle\DocumentBundle\Entity\CustomDocument\Test();
      die(var_dump($test));
      return new $fqcn();
      try {
          return $deletMe = new \DocDigital\Bundle\DocumentBundle\Entity\CustomDocument\Test1();
          return new $fqcn();
      } catch (\Exception $exc) {
          sprintf("Can't instantiate %s due to the following: \n  %s", $fqcn, $exc-&gt;getTraceAsString());
      }
  }
  </code></pre>
  
  <p>always with the same result:</p>
  
  <pre><code>php.CRITICAL: Fatal Error: Class 'bundle\Entity\namespace\Test' not found
  </code></pre>
  
  <p>Any help is appreciated. </p>
  
  <p>Thanks! </p>