PhpStorm 2023.3 Help

Add files and folders to projects

To add a new file or directory to your project:

  1. In the Project tool window (Alt+1), select the directory in which you want the new item to be created and do any of the following:

    • Select File | New from the main menu.

    • Right-click the directory and select New from the context menu.

    • Press Alt+Insert.

  2. Select the item type from the list.

    You can select File or Directory to create an empty file or directory, or use a file template with a predefined file extension and some initial contents.

    New item types list
  3. In the dialog that opens, specify the item name (and other parameters if prompted by the template) and press Enter.

Add PHP classes

PhpStorm assumes that the namespaces in your project are arranged in compliance with the PSR-0/PSR-4 standard and enforces you to retain the folder structure and the namespace hierarchy in accordance with this standard when creating PHP classes.

When you specify the folder where the file that implements the new class will be stored, PhpStorm automatically updates the namespace for the class.

  1. In the Project tool window Alt+1, select the directory in which you want to create a new PHP class and press Alt+Insert.

    Alternatively, right-click the corresponding directory and select New from the context menu, or select File | New from the main menu.

  2. In the New window that opens, select PHP Class to open the Create New PHP Class dialog.

    Create New PHP Class dialog
  3. In the Create New PHP Class dialog, fill out the fields as follows:

    • Name: type the name of the class to be created.

      PhpStorm automatically fills in the specified name in the File name field. Additionally, PhpStorm sets the Template value automatically in case the provided class name follows the standard convention (that is, NameClass for classes, NameInterface for interfaces, and NameTrait for traits).

    • Namespace: specify the namespace to create the class in, By default, the field shows the namespace that corresponds to the folder from which the class creation was invoked.

      You can choose <global namespace from the list or change the namespace manually. Keep in mind that this may cause loading problems, since such namespace hierarchy will not meet the PSR-4 standards.

      You can also change the folder to store the file that will implement the new class, the change will also be reflected in the Namespace field.

    • Template: select the template for the created file. The available options are:

      • Class

      • Interface

      • Trait

      • Enum (available only with PHP 8.1 or later)

      • Your custom manually created file templates with the PHP file extension, if any.

        To set such a template as a default, select the Use as a default template checkbox. The default template will be selected automatically the next time you invoke the creation of a new class.

    • File extension: select the file extension from the list

  4. If you are creating a class or an interface, optionally choose the parent classes for it in the Parent classes area.

    • In the Extends field, type the name of the parent class that the current class extends. To use code completion, press Ctrl+Space.

    • In the Implements area, choose the interfaces that the created class implements (or the created interface extends):

      • To add an interface, click the Add Class button or press Alt+Insert. In the Choose Class dialog that opens, search for the desired interface either by name or by using the project tree view.

      • To remove an interface, click the Remove button or press Delete.

  5. Click OK to save the changes. A new class is created according to the selected template, with the specified namespace declaration added automatically.

Last modified: 25 March 2024