Search code examples
phpstorm

How to make PhpStorm add an import for root classes?


When I start typing a class name, and select a class from the dropdown, PhpStorm uses the short class name and automatically adds an import at the top of the file, which is very handy:

However, when I do the same for a root class, PhpStorm uses the FQCN, prepending \ to the class name, and adding no import statement at the top of the file:

Is there a way to configure PhpStorm to always use the short class name for root classes too?


Solution

  • Sure, just use appropriate option for Class drop-down box under PHP | Treat symbols from the global space section: make sure it's "prefer import" instead of "prefer FQN".

    That option is located at Settings/Preferences | Editor | General | Auto Import

    enter image description here