Creating PHP Classes, Interfaces, and Traits
PhpStorm supposes that the namespaces in your project are arranged in compliance with the PSR0 standard and enforces you to retain the folder structure and the namespace hierarchy in accordance with this standard when creating classes, interfaces, and traits.
When you specify the folder where the file that implements the new class will be stored, PhpStorm automatically updates the namespace for the class.
Creating PHP classes
- Do one of the following:
- In the Project Tool Window, select the directory in which you want to create a new class/interface/trait, and then choose on the main menu.
- Right-click the corresponding directory and select New from the context menu.
- Press Alt+Insert.
- Choose PHP Class. The Create New PHP Class dialog box opens.
- In the Name text box, type the name of the class/interface/trait to be created. PhpStorm automatically fills in the specified name in the File Name field.
- Specify the namespace to create the class/interface/trait in. By default, the Namespace field shows the namespace that corresponds to the folder from which the class/interface/trait creation was invoked.
You can choose <global namespace> from the drop-down list or change the namespace manually. Keep in mind that this may cause loading problems, since such namespace hierarchy will not meet the PSR0 standards.
You can also change the folder to store the file that will implement the new class/interface/trait, the change will also be reflected in the Namespace field.
- In the Template drop-down list, specify the template from which to create the file. The available options are as follows:
- Choose the file extension from the drop-down list.
When you click OK, a new class is created according to the PHP Class template, with the specified namespace declaration automatically added.