'How can I make PHPStorm auto-import namespaces in use statements?
I have checked the box for "Enable auto-import in namespace scope" in preferences, however when I select a class from the autocomplete, the FQN remains rather than placing it in a use statement. What am I doing wrong and how can I force phpstorm to auto-import these?
Solution 1:[1]
As of today (PhpStorm 2022.1), you should select prefer import
option in Editor > General > Autoimport
instead of prefer FQN
.
Solution 2:[2]
Make sure that the file where you performing this is actually properly namespaced (as that is the requirement for Enable auto-import in namespace scope
option).
If working in non-namepsaced file .. you should enable Enable auto-import in file scope
option (it is not enabled by default for better compatibility with older existing code reasons).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dawid Ohia |
Solution 2 |