5
votes

I have a PHP trait file : app\Lib\someTrait.php

Even though it is a PHP file (with .php extension), PHPStorm is unable to recognize it as a valid PHP file. The editor is not doing syntax highlighting for PHP code inside this file and it is pretty much displayed as normal text file.

I am trying to use this file from its namespace in to another class file and there also it is unable to recognize the file path using :

use app\Lib\someTrait;

I did composer dump-autoload and also :

File->Invalid Caches and restart

I also deleted this file and restarted PHPStorm and again added it back but still not able to resolve this issue.

Looks like something has gone weird when I created a first file with this file name and now even though I tried all option PHPStorm is not treating this file as PHP file.

But still PHPStorm is unable to recognize this file.

How can I fix this issue?

1
It does have an open php tag (<?php), right? And does your code actually work, but PhpStorm is complaining for no good reason? - Ethan
Try moving it to another location, see if that works. If works, then it's probably the file name that's the issue. - Ethan
BTW .. my final solution is that I have renamed the file. Moving the file with the same name in different folder does not work either. It appears to be some PhpStorm Index cache issue... or may be something else. Do not have a luxury to spend too much time on this. - Andy
Please post a screenshot or how the file looks in IDE (whole editor tab please). I'm interested in file icon + a bit of content. So far it sounds like common user misconfiguration when user does not pay attention to what happens on the screen. If I'm right -- no clearing caches etc will help and you will have the same issue in another project (with the same file name). So it's better just solve it right and not looking for "workarounds" - LazyOne
Oh .. so file icon in IDE is an "IP issue"? Sorry about my request for details then. You seem to be happy with your workaround (got it working one way or another) .. so no problem here any more I guess. - LazyOne

1 Answers

21
votes

File | Settings | Editor | File Types - search for that file (someTrait.php) in a "Text" file type. Once found - remove