Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

phpstorm

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

like image 346
tiagojsag Avatar asked Dec 07 '15 08:12

tiagojsag


3 Answers

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

like image 71
Wolfgang Blessen Avatar answered Nov 06 '22 21:11

Wolfgang Blessen


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

like image 29
Max Romanenko Avatar answered Nov 06 '22 21:11

Max Romanenko


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

like image 32
Kirill Rogovoy Avatar answered Nov 06 '22 21:11

Kirill Rogovoy