5

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?

14
  • 1
    It does have an open php tag (<?php), right? And does your code actually work, but PhpStorm is complaining for no good reason? Commented Oct 4, 2017 at 21:37
  • 1
    Try moving it to another location, see if that works. If works, then it's probably the file name that's the issue. Commented Oct 4, 2017 at 21:43
  • 1
    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. Commented Oct 4, 2017 at 22:05
  • 1
    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" Commented Oct 4, 2017 at 22:11
  • 2
    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. Commented Oct 4, 2017 at 22:48

2 Answers 2

21

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

Sign up to request clarification or add additional context in comments.

3 Comments

Simple but not so easily to think like a first problem ;) +1 I had a same problem with "Tools.php" file in PrestaShop.
Right on the money! I wonder how the *Trait.php got there in the first place.
I added it by mistake into the Auto-detect file type by content category. Needless to say it was half an hour quite productive.
0

for me works: File -> Manage IDE Settings -> Restore to Default Settings

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.