On this page:

Basics

IntelliJ IDEA creates stubs of PHPDoc blocks on typing the opening tag /** and pressing or or or Enter, or Enter, ^ M, , ⌃M, or ⌃M or pressing ⌘N, ⌃⏎, ⌘N or ⌃⏎⌃N, ⌃⏎, ⌃N or ⌃⏎⌘N, ⌃⏎, ⌘N or ⌃⏎^ N, ⌥ Insert, ⌃N or ⌃N⌥ Insert and appointing the method.function to document.

If this feature is applied to a method or a function, @param, @access, @static, @throws, @return, @var, and @abstract tags are created. In any other places IntelliJ IDEA adds an empty documentation stub.

If you need additional PHP-specific tags, IntelliJ IDEA provides code completion that suggests tag names that are relevant in the current context. If a certain tag has multiple values, the same code completion provides a list of available values.

In PHPDoc comments, IntelliJ IDEA supports formatting options in compliance with ZEND, PEAR, and other standards.

PHPDoc comments in your source code are available for the Quick Documentation Lookup feature and open for review on pressing F1, ⌃J, ⌃Button2 Click, F1, ⌃J or ⌃Button2 Click⌃J, ⌃Button2 Click, ⌃J or ⌃Button2 Click⌥Button2 Click, F2, ⌥Button2 Click or F2^ Q, ⌃Q or ⌃Q^ Q, ⌥ Button2 Click, ⌃Q, ⌥Button2 Click, ⌃Q or ⌥Button2 Click.

To enable or disable generation of documentation comments
  1. Open the Preferences dialog box, expand the Editor node, then expand General node, and click the Smart Keys page.
  2. In the Enter section, select or clear Insert documentation comment stub check box.
Generating a PHPDoc block for a method or a function
  1. To invoke PHPDoc block generation, do one of the following:
    • Place the caret before the method or function declaration, type the opening block comment /**, and press or or or Enter, or Enter, ^ M, , ⌃M, or ⌃M.
    • On the context menu anywhere in the editor, choose Generate, then choose Generate PHPDoc blocks, and choose the method or function to generate comments for.
    • Press ⌘N, ⌃⏎, ⌘N or ⌃⏎⌃N, ⌃⏎, ⌃N or ⌃⏎⌘N, ⌃⏎, ⌘N or ⌃⏎^ N, ⌥ Insert, ⌃N or ⌃N⌥ Insert, then choose Generate PHPDoc blocks, and choose the method or function to generate comments for.

    IntelliJ IDEA analyzes the appointed method or function, where possible extracts the data for method parameters, return values, variables, etc., and on this basis generates a stub of a documentation block.

  2. Describe the listed parameters and return values, where necessary.

    IntelliJ IDEA checks syntax in the comments and treats it according to the PHP Inspections settings.

Creating tags in a PHPDoc comment block

IntelliJ IDEA analyzes the appointed method or function, where possible extracts the data for method parameters, return values, variables, etc., and on this basis generates a stub of a documentation block. If necessary, you can fill in the missing information.

  1. In a PHPDoc block, select the desired empty line and press ⌃Space or ⌃Space⌃Space or ⌃Space⌃Space or ⌃Space^ Space, ⌃Space or ⌃Space⌥ Slash, ⌥/ or ⌥/.
  2. Select the relevant tag from the suggestion list.
  3. If the entered tag has several values, press ⌃Space or ⌃Space⌃Space or ⌃Space⌃Space or ⌃Space^ Space, ⌃Space or ⌃Space⌥ Slash, ⌥/ or ⌥/ and select the desired value from the suggestion list.
Inspecting PHPDoc comments

IntelliJ IDEA provides a set of predefined code inspections targeted at PHPDoc blocks. These inspections check whether classes, methods, functions, variables, and constants are supplied with a PHPDoc comment and whether the tags in the comment match the documented item.

  • To enable or disable an inspection:
    1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X, and click Inspections under Editor.
    2. On the Inspections page that opens, expand the PHPDoc node under the PHP node. The list of predefined inspections is displayed.
    3. To enable or disable an inspection, select or clear the check box next to it.
  • To have IntelliJ IDEA check that PHPDoc comments are provided for all code constructs of a certain type:
    1. Select the check box next to the Missing PHPDoc Comment inspection.
    2. In the Options area, select the check boxes next to the required code construct type: class, method, function, variable, or constant.
    3. To suppress reporting a Missing PHPDoc Comment error if a method or function does not contain any parameters and/or return values, select the Skip if empty.
Configuring formatting inside PHPDoc comments

You can configure the appearance of PHPDoc comments and the presentation of class names in the Settings dialog box, on the PHPDoc tab of the Code Style. PHP under the Code Style node. Note that the tag for properties is no longer configurable, the default @var tag is inserted automatically. See https://github.com/phpDocumentor/fig-standards/pull/55 for details.

  1. Open the Preferences dialog box, click Code Style, then click PHP, and switch to the PHPDoc tab.
  2. Configure the alignment by selecting or clearing the check boxes in the tab.
  3. Specify how you want IntelliJ IDEA to present class names for properties, function parameters, return and throws values, etc. by selecting or clearing the Use fully-qualified class names check box.