"Another Class is Declared in the Same File", except it isn't!

Hi,

This is driving me crazy.

I have this project where some php files (not all) have all classes within them flagged for "Another Class is Declared in the Same File". I can just create a new random class and it will be flagged so, immediately.

I've checked Preferences > Directories, and only the Source Directory is listed, no other strange folders.

Also checked Preferences > Languages & Frameworks > PHP > Included Directories, and there's only the Wordpress folder (which is a sibling folder to the project in question, not nested or anything).

I'm not using any framework like Laravel which might keep backups/duplicates etc. 

Any ideas?

0

Hi there,

Please try "File | Invalidate Caches..." and restart IDE (if you have not tried it yet).

If it does not help -- please provide such file, ideally a project. + screenshot of how it looks (whole IDE window with error message visible in particular).

Try also checking what Inspection reports it (via quick fix Alt+Enter menu if you know how it works; otherwise just use "Code | Inspect Code..." on problematic file).

0
Avatar
Permanently deleted user

Hello,

> some php files (not all) have all classes within them flagged for "Another Class is Declared in the Same File"

So does it mean that each of these PHP files have several classes within it? like

<?php
class NewClass {
//something
}
class AnotherClass {
//something
}
0

Hi Vladimir,

Exactly.

If I hover over NewClass or AnotherClass, it will say "Another Class is Declared in the Same File". But if I search the Project for NewClass or AnotherClass, only this one declaration is shown. 

If I have to guess, something is pointing to my folders twice, though I can't seem to find it (see original post).

Oh, and I've tried "File > Invalidate Caches" and restarted too. No difference.

0

Chris, if I got you right, only one certain project is affected.
What if you copy the project into a new dir leaving .idea aside, and create a new project out of the this dir - it's not affected, is it?
If it's not, please remove all sources from the affected project, create a new file with the same name as one of affected files, and try it there.
If the issue persists, we'll need your problematic .idea folder to find out what's happening there.

0

Hi Eugene,

Thanks for responding. Yes, only one project (and only a few files, see bottom) is affected.

I've tried:

1. copied the project over to a different (external) harddisk, removed .idea folder, and created a new project out of the new copy.

2. Unfortunately the classes still show the same "another class in same file" error.

3. To be sure, I also removed the .git repo and invalidated cache and restarted, no difference.

I've also searched the system for duplicates of this php file, and only two files exist, the original and the copy.

Adding a namespace doesn't change anything either.

I've also removed the Wordpress external library link, just to be sure, no difference. I've only got the PHP Runtime External Library connected, nothing else.

I've also tried alt-Enter on the class and by trial-and-error (removing each scope in turn) found that the 'error scope' is in "Project Files", and not "Everywhere else"

---

So far I've found three php files with this problem. The only things in common with the three that I can think of are:

(1) they were created by me (as opposed to an external plugin downloaded from remote host), originally by File > New from within phpStorm. 

(2) I've worked on them a lot

(3) they contain classes

Any new random class I add to these files will show the same error.

That said, I've tried to reproduce the error on other php files I've created that weren't worked on a lot, and that didn't originally have classes: so I tried creating a new class, and it's ok, no error.

 

0

Wow that must be a tricky one.

What else can be tried here:

  1. It's not really likely, but just in case please disable all custom plugins (Settings/Preferences | Plugins | Show: Custom) and check how it's going after another Invalidate Caches invocation.
  2. Even less likely (invalidation should've covered that), but we're running out of options anyway - try starting PhpStorm with an empty config not importing the previous one (you need to rename the directory(ies) PhpStorm keeps configs/caches/plugins in).

If neither helped, please try opening the same project on a different machine (a VM would do just fine). If the issue persists there as well, we'll definitely need the project as a sample. You can submit it on YouTrack setting limited visibility to the attachment.

Please share the resulting issue link here if things come all the way down to this. I hope they don't.

0

Ok, 1. above fixed it. Thank you!!

There were two custom plugins (ANSI Highlighter and log reader). Disabled the two, restarted and everything's fine.

Funny thing is, I've re-enabled them again and restarted, and the project re-indexed, and everything's still fine.

EDIT: 

Nope, it didn't work :(   Maybe phpStorm was still indexing in the background. But after a while, the error appeared again. Will do more troubleshooting and report here.

0

Tried everything, didn't work. 

So I created YouTrack bug report here: https://youtrack.jetbrains.com/issue/WI-42365

Thanks!

0

请先登录再写评论。