keevitaja's avatar

PhpStorm warning: Multiple definitions exists for class ...

I am getting warnings with Classes like Model, Controller

https://dl.dropboxusercontent.com/u/60672885/warning.png

Is there a way to fix this?

Using PhpStorm 8

0 likes
14 replies
keevitaja's avatar

So without this package you do not get the warnings?

keevitaja's avatar
keevitaja
OP
Best Answer
Level 13

Found the solution. I can't explain it, but when i exclude the storage folder in Settings/Directories this warning goes away!

1 like
rawfan's avatar

This is old but here's a way to figure this out. On the class with multiple definitions hit CTRL+B to get a list of the definitions available. Now you see who's competing with each other. In my case it was ide-helper vs some classes in codeception. I just went to the project settings and excluded the codeception vendor dir.

7 likes
kontrast's avatar

I've the same problem using Laravel 5 and both seems to be important.

Model .../vendor/laravel/framework/src/Illuminate/Database/Eloquent

Model .../storage/framework/compiled.php

kontrast's avatar

@JarekTkaczyk Thanks for the quick answer. The warning disappears but it didn't solve my problem. I haven't put "namespace App;" in my own class cause it isn't in the L5-from-scratch tutorial either. After doing that everything is working.

browner12's avatar

so the explanation is that laravel/composer is able to generate a compiled.php file that puts all of your class definitions into one big file that can help with load times (not always true). this is another option in addition to autoloading (with something like PSR-0 or PSR-4). because this compiled.php file exists, all of your classes are technically defined twice (although the definition is the same). this confuses phpstorm, so all you need to do is 'exclude' the compiled file from PHPStorm's indexing. depending on which version of laravel you use, this may be in different places, including bootstrap/cache for 5.1 and storage/framework for 5.0.

1 like
sitesense's avatar

+1 @browner12 - it's simply that you have run php artisan optimize or something similar and debug is false.

This creates the compiled.php file, however this can be ignored by your IDE.

To test this you can run php artisan clear-compiled and see the difference.

1 like
alexman's avatar

Note: I resolved this by going to Preferences-> Languages & Frameworks-> PHP; and then under Include path, remove the conflicting path. (In my case a package reference in the vendor directory to a package I was developing inside my Laravel project)

2 likes
greg_rs's avatar

@ALEXMAN - I went and looked and I had piles of includes from something like 5 laravel projects ago! Bizarre!

1 like
EBonocore's avatar

Just had the same issue while upgrading from Laravel 9 to 10. The IDE was complaining about multiple definitions in several files. My solution was to delete _laravel_idea from the vendor directory.

foantje's avatar

@EBonocore

composer require --dev barryvdh/laravel-ide-helper

php artisan ide-helper:generate

Optionally, you can also generate PHPDoc blocks for models:

php artisan ide-helper:models

Please or to participate in this conversation.