Skip to content

PHPDoc tags and annotations

USAMI Kenta edited this page Sep 21, 2017 · 3 revisions

Original version is in https://github.com/zonuexe/emacs-php-info/wiki/PHPDoc-tags-and-annotations (Japanese).

"tag" vs "annotation"

Comment notation with @ such as @exapmle is called tag or annotation. These are similar, but they have different characteristics.

annotation

/**
 * @Annotation
 * @Target("CLASS")
 */

Annotations are introduced mainly by Doctrine. It has syntax with complex expressions with parentheses. Annotations typically contain capital letters and backslashes, so they have slightly different characteristics from tags.

The definition by Doctrine is in Doctrine Annotations — Doctrine Common 2.1 documentation. The parser implementation is doctrine/annotations: Annotations Docblock Parser.

tag

/**
 * @deprecated
 * @license MIT
 */

Tag syntax is relatively simple compared to annotation. Tokens are generally divided by spaces and their parsing is basically easy. (However, for each tag corresponding is required.)

phpDocumentor

These tags are defined in List of tags and Tag reference.

  • @api
  • @author
  • @category
  • @copyright
  • @deprecated
  • @example
  • @filesource
  • @global
  • @ignore
  • @internal
  • @license
  • @link
  • @method
  • @package
  • @param
  • @property
  • @property-read
  • @property-write
  • @return
  • @see
  • @since
  • @source
  • @subpackage
  • @throws
  • @todo
  • @uses and @used-by
  • @var
  • @version

Phan

These tags are defined in Annotating Your Source Code · phan/phan Wiki.

  • @var
  • @param
  • @return
  • @method
  • @deprecated
  • @internal
  • @suppress
  • @property
  • @override
  • @phan-closure-scope

PhpStorm

The proprietary tags implemented in PhpStorm are not documented and we do not have those lists.

Clone this wiki locally