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 Brainvire. The employees are...
Mr. Manjesh Singh
Brainvire is a professional company with professional developers who understand the problems that we are facing as a company. Outsourcing...
Mr. Clarke Verdel
BIG THANK YOU to Brainvire team for all their smart work and fantastic services. We are very pleased with the...
Mr. Greg Pietsch
Just wanted to say massive thanks for all the help from the Brainvire team. After years of having a website...
Mr. Rohit Singla
Chad Gundry, the CEO of says that he has worked extensively with Brainvire team since last 6 to 7...
Mr. Chad Gundry

Latest Happenings

  • 04 Oct 2016
    Brainvire Making great Strides with Symfony Development Services [ + ]
  • 29 Sep 2016
    Brainvire augments its List of Offerings with Magento Sears Integration Services [ + ]