It is a good practice to write a documentation comment above the function or class to explain it’s functionality to other developers. In the future, if we need to modify the function, we can easily understand the reason for creating that function without checking the entire code and modify it according to the application requirements. WordPress core classes provides the best example of the PHP documentation comment. Here is an example of a WordPress core class.

Write php documentation comment

PHP documentation comment structure

Here is the basic structure of PHP documentation comments for class and function, and we can use it in our PHP code.

Class documentation comment

/**
 * Default strings and translation support for those.
 * @package your-package-name
 * @version 1.0.0
 */

Explanation

  1. The first line is for explaining the functionality of the class.
  2. @package is for the class package name.
  3. @version is for describing the class version.

Function documentation comment

/**
 * Default strings and translation support for those.
 * @since 0.1.0
 * @param string $page_title The page title, with extra context added.
 * @param string $title       The original page title.
 * @return string
 */

Explanation

  1. The first line is for explaining the functionality of the function.
  2. @since is for the version number to which the function has been added.
  3. @param is for describing function parameters and types.
  4. @return is the return type of the function.
Last Update: July 7, 2024
July 7, 2024 187 Mahbub Alam KhanGeneral, Php
Total 0 Votes
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Back To Top