PhpStorm 2023.2 Help

Libraries and library roots

A library is a third-party file or set of files used in a project as is.

PHP libraries are most commonly managed in projects by Composer, which declares them as dependencies and installs to folders in the vendor directory. To distinguish libraries from the project files but still include their classes and methods to the IDE's internal knowledge, PhpStorm marks library folders as library roots. For more information, refer to PHP library roots.

JavaScript libraries can be configured at the global (IDE) or project level, which defines reusability of the library within the IDE. For more information, refer to Configuring Javascript libraries.

PHP library roots

In PhpStorm, a library root is a folder with library files that is marked as Excluded and at the same time is added as a PHP include path in Settings | PHP | Include Path. PhpStorm treats this root type in the following way:

  • Despite being excluded, libraries are still indexed, which means that the classes and methods from libraries are available in auto-completion, search, reference resolution, and so on, but on a second-class citizen principle. You can exclude Composer-managed libraries from indexing completely.

  • Libraries are excluded from error checks.

  • All library files open in the Reader mode and are protected with a Non-Project Files Protection pop-up on modification attempts, such as direct intentional editing or update result from refactoring.

    Non-Project Files Protection

In the Project tool window, library roots are marked with a colored background only:

Library roots in Project tool window

View library roots in a project

  • By default, all folders under the vendor directory are considered to be library roots by PhpStorm. Such folders are added to Settings | PHP | Include Path automatically.

    PHP Include Path list
  • The External Libraries node in the Project tool window contains library roots added as PHP include paths manually.

    External Libraries in Project tool window

    If the project contains only Composer-managed libraries, double-clicking External Libraries opens the list of library roots in Settings | PHP | Include Path.

Exclude libraries from indexing

You can exclude the contents of the vendor directory from indexing. To do so:

  1. In the Settings dialog (Control+Alt+S), go to PHP | Composer, clear the Add packages as libraries checkbox, and apply the changes.

    Clear Add packages as libraries checkbox

    All folders under the vendor directory are now converted into regular project folders.

  2. Select the folder you want to exclude in the Project tool window, and from its context menu, select Mark Directory as | Excluded.

Besides Composer, you can use a third-party tool or framework as a library in your project in the following ways:

In either case, you can use exploded and archived tool sources. PhpStorm recognizes most popular zip and TAR.GZ formats as well as the PHP native PHAR format.

Last modified: 27 October 2023