Talk To Us For FREE

We are in the Business of Support and that starts before you even become a client.

  • Please prove you are human by selecting the Tree.

How to Find Duplicate Classes In Symfony

Categories : Article, Symfony

Sometimes, Symfony presents unique problems with classes being silently redeclared. So much so that you might think that you are making changes to one file but your changes don’t have any effect.

How to Find Duplicate Classes In Symfony

Declaring a class in two separate files with that have the same filename, results in Symfony (Or similar frameworks) that have an autoloader to load only the first file that it gets to.

This is used by some programmers intentionally to override a class on purpose. For example, in a third party plugin where you cannot control the original class and it’s a challenge or it’s impossible to extend the third party plug in. That’s how this can be beneficial, but when you do not want to override it, it poses a challenge.

It can cause obstructions in a lot of situations. When you are deploying over a legacy FTP connection or rsync or gross, you might just end up with the same file in two different locations. Moving classes between deployments might end up loading classes twice and in two locations. Well, unless the entire code is removed from remote server, you will never realize that just one file is being used.

In large projects however, it sometimes happens that a class file gets duplicated and no one notices. Take for example, there are three developers working on similar platforms as well as PHP versions. They make changes to the class file that they perceive as “right” which turns out to be the file you expected to be loaded – not the duplicate one that people apparently forgot about. The duplicate file goes unnoticed by all developers – until some subtle differences in system configuration changes the order of the autoloaded files.

Here’s how your PHP class files should be named:


With this, you can run a report of duplicate class names

find . -name ‘*.class.php’ | xargs basename | sort | uniq –d

or in Mac OS, taking advantage of the native indexing:

mdfind -onlyin . -name ‘.class.php -actions.class.php -components.class.php’ | xargs basename | sort | uniq –d

After that, you can check each class for duplicate classes and determine which one you actually want to use and easily eliminate the ones that you know you aren’t going to use.

[Total: 0    Average: 0/5]

Client Saying

If you're starting a new business or want to upgrade an existing site, I strongly recommend…
Mr. Manjesh Singh
Daniel Coburn, the president of gives the honest opinion regarding his experience working with Brainvire…
Mr. Daniel Coburn
Chad Gundry, the CEO of says that he has worked extensively with Brainvire team since…
Mr. Chad Gundry
The best thing about Brainvire is Compatibility. Whenever we have a query Brainvire is always ready…
Mr Craig Agranoff
Brainvire is a professional company with professional developers who understand the problems that we are facing…
Mr. Clarke Verdel

Latest Happenings

  • 17 Mar 2017
    Brainvire - Walmart Collaboration Hits Another Retail Height [ + ]
  • 03 Mar 2017
    Brainvire’s Vision for Becoming the Global Mobile Dominant Strengthens with MWC17 [ + ]