plugin icon indicating copy to clipboard operation
plugin copied to clipboard

Multiple definitions exist for class 'Collection'

Open smares opened this issue 5 months ago • 8 comments

When using Laravel Idea with code generation, PhpStorm warns me that multiple definitions exist for class 'Collection' for example in my Lumen 10 project, one in _ide_helper_macro and one in _ide_helper_macro_static. Is this intended behavior?

smares avatar Aug 12 '25 09:08 smares

It seems there is no Collection class in the project, but some library added a macro method to it...

So, Lumen framework doesn't contain the Collection class by default?

adelf avatar Aug 12 '25 16:08 adelf

It does, https://github.com/laravel/lumen-framework/blob/10.x/composer.json#L24

smares avatar Aug 12 '25 17:08 smares

Looks like PhpStorm forgot about the original Collection class. Could you make main menu > File > Invalidate Caches...?

adelf avatar Aug 12 '25 17:08 adelf

Didn't help. 😟 Wondering if it's because of Laravel Scout because _ide_helper_macro_static.php and _ide_helper_macro.php both contain:

...
namespace Illuminate\Support {

    /**
     * @method static void searchable()
     * @method static void unsearchable()
     */
    class Collection {}
}

smares avatar Aug 13 '25 12:08 smares

So, there is Illuminate\Support\Collection in this project, but PhpStorm sees only these two from helper files? Looks like a PhpStorm bug...

adelf avatar Aug 14 '25 05:08 adelf

OK this is weird, I now moved the path of the generated files to <root>/vendor/_laravel_idea (previously had them in <root>/.laravel_idea) and now I see 3 hits, one for Illuminate\Support\Collection and the two aforementioned by Laravel Idea.

But is it expected that every occurance of use Illuminate\Support\Collection; now triggers the warning? I was hoping that PhpStorm knows that they all belong to the same namespace and class.

Image

smares avatar Aug 14 '25 09:08 smares

This happens to me after the latest update...

Image Image

emaia avatar Aug 14 '25 23:08 emaia

We did some fixes in 11.5, and they can fix this issue too. Could you update and check?

adelf avatar Nov 09 '25 07:11 adelf