title: symfony2 fatal error Cannot redeclare class
body: <p>Ok, I've been at this for two hours now and I see some other people have had this error, but I can't seem to match their causes/resolutions with mine.</p>
  
  <p>Fatal error: require() [function.require]: Cannot redeclare class companycontroller in /var/www/biztv_symfony/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php on line 55</p>
  
  <p>The terminal gives a better error message pointing me to the end clause of the actual class that it reports having trouble with (trying to redeclare).</p>
  
  <p>If I remove or rename the file companyController.php it throws a Symfony2 error saying that the it went looking for the class but didn't find it where it was expected.</p>
  
  <p>If I put the file back in its place, apache throws a php error saying that the class companyController can't be redeclared.</p>
  
  <p>I only have it once?!</p>
  
  <p>Here is the entire class... if anyone has patience to try and help me out...</p>
  
  <pre><code>&lt;?php
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  
  use BizTV\BackendBundle\Entity\company;
  use BizTV\BackendBundle\Form\companyType;
  
  /**
   * company controller
   *
   */
  
  class companyController extends Controller
  {
      /**
       * Lists all company entities.
       *
       */
      public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
          $entities = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;findAll();
  
          return $this-&gt;render('BizTVBackendBundle:company:index.html.twig', array(
              'entities' =&gt; $entities
          ));
      }
  
      /**
       * Finds and displays a company entity.
       *
       */
      public function showAction($id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
          $entity = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find company entity.');
          }
  
          $deleteForm = $this-&gt;createDeleteForm($id);
  
          return $this-&gt;render('BizTVBackendBundle:company:show.html.twig', array(
              'entity'      =&gt; $entity,
              'delete_form' =&gt; $deleteForm-&gt;createView(),
  
          ));
      }
  
      /**
       * Displays a form to create a new company entity.
       *
       */
      public function newAction()
      {
          $entity = new company();
          $form   = $this-&gt;createForm(new companyType(), $entity);
  
          return $this-&gt;render('BizTVBackendBundle:company:new.html.twig', array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView()
          ));
      }
  
      /**
       * Creates a new company entity.
       *
       */
      public function createAction()
      {
          $entity  = new company();
          $request = $this-&gt;getRequest();
          $form    = $this-&gt;createForm(new companyType(), $entity);
          $form-&gt;bindRequest($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              /* Create adminuser for this company to go along with it */
              $userManager = $this-&gt;container-&gt;get('fos_user.user_manager');
              $user = $userManager-&gt;createUser();
  
              //make password (same as username)
              $encoder = $this-&gt;container-&gt;get('security.encoder_factory')-&gt;getEncoder($user); //get encoder for hashing pwd later
              $tempPassword = $entity-&gt;getCompanyName(); //set password to equal company name
  
              //Get company
              $tempCompanyId = $entity-&gt;getId(); //get the id of the just-inserted company (so that we can retrieve that company object below for relating it to the user object later)
              $tempCompany = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;find($tempCompanyId); //get the company object that this admin-user will belong to
  
              $user-&gt;setUsername($entity-&gt;getCompanyName() . "/admin"); //set username to $company/admin
              $user-&gt;setEmail('admin.'.$entity-&gt;getCompanyName().'@example.com'); //set email to non-functioning (@example)
              $user-&gt;setPassword($encoder-&gt;encodePassword($tempPassword, $user-&gt;getSalt())); //set password with hash
              $user-&gt;setCompany($tempCompany); //set company for this user            
              $user-&gt;setConfirmationToken(null); //we don't need email confirmation of account
              $user-&gt;setEnabled(true); //without a confirmation token, we of course also need to flag the account as enabled manually
              $user-&gt;addRole('ROLE_ADMIN');
  
              $userManager-&gt;updateUser($user);
  
              return $this-&gt;redirect($this-&gt;generateUrl('company_show', array('id' =&gt; $entity-&gt;getId())));
  
          }
  
          return $this-&gt;render('BizTVBackendBundle:company:new.html.twig', array(
              'entity' =&gt; $entity,
              'form'   =&gt; $form-&gt;createView()
          ));
      }
  
      /**
       * Displays a form to edit an existing company entity.
       *
       */
      public function editAction($id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
          $entity = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find company entity.');
          }
  
          $editForm = $this-&gt;createForm(new companyType(), $entity);
          $deleteForm = $this-&gt;createDeleteForm($id);
  
          return $this-&gt;render('BizTVBackendBundle:company:edit.html.twig', array(
              'entity'      =&gt; $entity,
              'edit_form'   =&gt; $editForm-&gt;createView(),
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          ));
      }
  
      /**
       * Edits an existing company entity.
       *
       */
      public function updateAction($id)
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
          $entity = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find company entity.');
          }
  
          $editForm   = $this-&gt;createForm(new companyType(), $entity);
          $deleteForm = $this-&gt;createDeleteForm($id);
  
          $request = $this-&gt;getRequest();
  
          $editForm-&gt;bindRequest($request);
  
          if ($editForm-&gt;isValid()) {
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('company_edit', array('id' =&gt; $id)));
          }
  
          return $this-&gt;render('BizTVBackendBundle:company:edit.html.twig', array(
              'entity'      =&gt; $entity,
              'edit_form'   =&gt; $editForm-&gt;createView(),
              'delete_form' =&gt; $deleteForm-&gt;createView(),
          ));
      }
  
      /**
       * Deletes a company entity.
       *
       */
      public function deleteAction($id)
      {
          $form = $this-&gt;createDeleteForm($id);
          $request = $this-&gt;getRequest();
  
          $form-&gt;bindRequest($request);
  
          if ($form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
              $entity = $em-&gt;getRepository('BizTVBackendBundle:company')-&gt;find($id);
  
              if (!$entity) {
                  throw $this-&gt;createNotFoundException('Unable to find company entity.');
              }
  
              $em-&gt;remove($entity);
              $em-&gt;flush();
          }
  
          return $this-&gt;redirect($this-&gt;generateUrl('company'));
      }
  
      private function createDeleteForm($id)
      {
          return $this-&gt;createFormBuilder(array('id' =&gt; $id))
              -&gt;add('id', 'hidden')
              -&gt;getForm()
          ;
      }
  }
  </code></pre>