Add files and folders to projects
To add a new file or directory to your project:
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:
Selectfrom the main menu.
Right-click the directory and select New from the context menu.
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.
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.
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 from the main menu.
In the New window that opens, select PHP Class to open the Create New PHP Class dialog.
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,
NameInterfacefor interfaces, and
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:
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
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 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 or press Delete.
Click OK to save the changes. A new class is created according to the selected template, with the specified namespace declaration added automatically.