1
votes

I am trying to debug the error "Fatal error: Cannot redeclare class Acme\UserBundle\Entity\User in C:\wamp\www\Symfony\src\Acme\UserBundle\entity\User.php on line 15" in my command window when I want to create Mysql tables using the Doctrine command "php app/console doctrine:schema:update --force".

Here is the top of my entity code:

namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Acme\UserBundle\Entity\User
 *
 * @ORM\Table(name="acme_users")
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 */
class User implements UserInterface, \Serializable
{    
 //...

To see where I could have double-declared my "User" class, I have renamed in into "User_alias" and cleared my cache (using the "php app/console cache:clear" command). The command window gives me then the error "The table with name 'basededonne.acme_users' already exists.'. However, I do not see this table in phpmyadmin. In addition, my browser gives me the error "FatalErrorException in User.php line 15: Compile Error: Cannot redeclare class Acme\UserBundle\Entity\User_alias" (I did not have error in my browser when I used the "User" class).

Could anyone give me some other options to explore to resolve this issue? There is a bigger picture that I am currently missing I guess.

1
One possibility is that you had taken back-up of your User.php with another file name. So the search whole project with class User, if it is there? rename it. And delete the cache manually and then update your schema. - herr

1 Answers

2
votes

In your User_alias.php you have class User definition.

While you are trying to clear your cache in the warmup part of this command symfony generates some cache files based on your project files. And so after visiting class User in User.php it again visit class User in User_alias.php and throw an error.

Try to rename your class in User_alias.php and all will be working fine.