PHPDoc Completion
PHPDoc block is completed by typing '/**
' or using a code action.
PHPDoc tags are completed by typing '@
' inside the PHPDoc block.
Type names inside PHPDoc are completed as well. It is triggered automatically in most cases, or use the corresponding shortcut for editor.action.triggerSuggest
command (Ctrl+Space
on Windows).
PHPDoc Generation
The PHPDoc block is generated automatically by typing '/**
' above the following constructs:
- function
- class
- namespace
- properties
- constants
The generated PHPDoc block contains inferred types, exceptions, and lists function parameters. In case of a function override, the PHPDoc block may contain {@inheritDoc}
annotation instead, so it inherits all the information from the base class properly.
PHPDoc Type Hints
Type hints within PHPDoc comments are analyzed and used for purposes of code completion and type analysis. See the sample below for type hinting the parameter $x
of function foo
. For more details on code completion see completion documentation.
<?php
/**
* @param array|bool $x The parameter description.
*/
function foo($x) {
//
}
Type hints are supported within the vast array of tags, including standard Doc Comment tags (i.e. @return
, @param
), PhpStan tags (i.e. @phpstan-assert
, @phpstan-template
, ..), or Psalm. They do support the generic type annotations, WordPress type annotations, MediaWiki annotations, and more.
Additionally, type hints are highlighted with colors defined your Visual Studio Code Theme. This handles generic type annotations, structured objects, structured array syntax, specific colors for interfaces, enum, traits.