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).

Share:
11,658

Related videos on Youtube

KinsDotNet
Author by

KinsDotNet

I'm a PHP developer and general system administrator for a college.

Updated on October 21, 2022

Comments

  • KinsDotNet
    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
    Aerendir over 7 years
  • Umur Karagöz
    Umur Karagöz almost 6 years
    Also Enable auto-import from the global scope seemingly forces to use use statements instead of putting a prepending a backslash.
  • LazyOne
    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)