symfony2 fatal error Cannot redeclare class

China☆狼群 提交于 2019-11-30 08:28:40

So, turns out that was a clumpsy typo by moi there.

But for anyone else who runs into this error message in Symfony2:

Fatal error: require() [function.require]: Cannot redeclare class...

Here is a hint: check if you have accidentally deleted or typo:ed the namespace in the file that contains the definition of the class that php claims it is trying to re-define.

The php error message doesn't really give you a clue to look for that... =)

redeclare class - Likely there is tow classes with the same name

Sometimes, if you got seduced by copy/paste, check your classnames, namespaces and for other "typos" that could have happened. (copy/paste is the devil of programming :/)

Similar to other answers, in my case I had renamed the class but not the containing file. Every class should be declared in a file with the same name. So check that, too.

In my case, it was a use statement under the namespace which used the same classname (but another path).

namespace Bsz\RecordTab;
use \Bsz\Config\Libraries; // I used  this in constructor
class Libraries 
{
...
}

Without the use directive, it Worked

Personally, I juste removed cache manually and it worked

rm -rf app/cache/*

Clearing cache was not fixing my problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!