PhpStorm 2016.2 Help

Creating PHP Classes, Interfaces, and Traits

On this page:

Basics

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

  1. In the Project tool window, select the folder that corresponds to the namespace where you want a new class/interface/trait created and then choose New | PHP Class on the context menu of the selection. The Create New PHP Class dialog box opens.
  2. 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.
  3. 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 keeping mind that this may cause problems with loading as 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 be also reflected in the Namespace field.

  4. In the Kind drop-down list, specify what to create, the available options are:
  5. 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.

See Also

Last modified: 24 November 2016