Creating PHP Classes
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 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.
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, and then choose on the main menu.
Right-click the corresponding directory and select New from the context menu.
Choose PHP Class. The Create New PHP Class dialog box opens.
In the Name text box, type the name of the class to be created. PhpStorm automatically fills in the specified name in the File Name field.
- Specify the namespace to create the class in. By default, the Namespace field shows the namespace that corresponds to the folder from which the class 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, 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:
- The set of PhpStorm bundled templates:
- Your own set of manually created file templates having the php file extension.
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.
Choose the file extension from the drop-down list.
When you click OK, a new class is created according to the selected template, with the specified namespace declaration added automatically.