How can I make PHPStorm auto-import namespaces in use statements?
11,658
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).
Related videos on Youtube
Author by
KinsDotNet
I'm a PHP developer and general system administrator for a college.
Updated on October 21, 2022Comments
-
KinsDotNet over 1 year
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?
-
Aerendir over 7 yearsHere the documentation: jetbrains.com/help/phpstorm/2016.2/auto-import.html
-
Umur Karagöz almost 6 yearsAlso
Enable auto-import from the global scope
seemingly forces to useuse
statements instead of putting a prepending a backslash. -
LazyOne almost 6 years@UmurKaragöz That is correct .. as that's what "import" means. In 2018.1 they have introduced a better control .. and you now can use prepending slash instead .. or rely on fallback logic. But that's general (covers file and namespace scope at the same time)