Home » Php » php – Properly handle PHPStorm's "multiple definitions exist for class"

php – Properly handle PHPStorm's "multiple definitions exist for class"

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am currently working on a PHP project that uses composer to manage 3rd party dependencies. This project has an /installer subproject which, like the name suggests, contains a small tool that handles the installation and initial configuration of the “main” project. The installer tool also uses composer to handle its dependencies, which are kept separate from the main project’s libs.

For convenience reasons, these two projects go into the same git project, and as such in the same PHPStorm project. As both projects dependencies sometimes overlap, I often get a “Multiple definitions exist for class” warning. While this is neither unexpected nor a major issue, I would like to know if there is actually a way to tell PHPStorm “hey, treat everything inside /installer as an independent project, and don’t cross-check classes with the outside scope`.

Thanks

How to&Answers:

You can disable this inspection (works for at least PHPStorm 9.0 or later):

Settings -> Editor -> Inspections -> PHP -> Undefined -> Undefined class

Uncheck Options (right bottom) -> Don’t report multiple class declaration potential problems

Answer:

It is possible to mark directory as Excluded, so PHPStorm will just hide it and stop index files inside, so no warnings.
But in the same time it will be impossible to view (read) that files.

Right click directory (in your case /installer) in Project pane and choose Mark Directory As -> Excluded

Answer:

You can right click the files in the Project Explorer and mark them as “Plain Text”, so these classes are not interpreted as source code.

The better way: Use Namespaces