Troubleshooting (symfony) – “Cannot redeclare class” error

This blog entry suggests how to recover from the error shown as below.

Error message

Fatal error: Cannot redeclare class base{model}peer in /var/www/html/{project}/lib/model/om/Base{model}Peer.php on line 4


PHP Fatal error:  Cannot redefine class constant Base{model}Peer::COUNT in /var/www/html/{project}/lib/model/om/Base{model}Peer.php on line 170
$ symfony propel-generate-crud frontend xxxx Xxxx 

PHP Fatal error:  Cannot redefine class constant BaseXxxxPeer::yyyy in /var/www/html/keiba2/lib/model/om/BaseXxxxPeer.php on line xxx

Solution 1

The most likely cause of the redeclaration error is that you have tried to use a namespace (MySQL reserved word) mistakenly as a column name. Edit schema.yml in the following steps.

  1. Open configschema.yml
  2. Find redundancy in column names.
  3. If you can not find any redundancy, check if MySQL reserved words have been used as a column name. Be careful not to use words such as “count” which are already assigned to Propel.

Change column names according to the error message, save the file and close.

Redefine the model and SQL by symfony propel-build-all

Solution 2

If the above-mentioned method did not work, the project name which refers to lib class may be incorrect. Check the settings of properties.ini. This problem often occurs when you create a new project by copying a previous project.

  1. vi configproperties.ini
  2. Enter the folder name of the project in name=xx, which does not have to be enclosed by quotation marks, save and quit.
  3. symfony cc
This post is also available in other languages.