symfony2 fatal error Cannot redeclare class

后端 未结 6 1259
野趣味
野趣味 2020-12-31 02:06

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.

Fatal error:

相关标签:
6条回答
  • 2020-12-31 02:29

    Personally, I juste removed cache manually and it worked

    rm -rf app/cache/*
    

    Clearing cache was not fixing my problem.

    0 讨论(0)
  • 2020-12-31 02:43

    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

    0 讨论(0)
  • 2020-12-31 02:44

    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 :/)

    0 讨论(0)
  • 2020-12-31 02:50

    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... =)

    0 讨论(0)
  • 2020-12-31 02:52

    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.

    0 讨论(0)
  • 2020-12-31 02:53

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

    0 讨论(0)
提交回复
热议问题