28

I'm new to PHP development, and I'm wondering if the community has any guidelines for inline documentation of code using comments. I'd love something like Python's PEP 257, but I'd settle for a format used by a popular document extraction tool, or even the documentation standard of a popular product.

jwhitlock
  • 4,572
  • 4
  • 39
  • 49

5 Answers5

14

The most widely used form of API documentation for PHP is phpDocumentor a.k.a. phpdoc. Quite a lot of IDEs are also able to extract information to improve auto-completion hints using phpDocumentor style API docs.

Person
  • 1,091
  • 1
  • 9
  • 14
Daniel Egeberg
  • 8,359
  • 31
  • 44
9

The phpdoc (phpDocumentor) style is common. It uses DocComments containing DocBlocks.

<?php
/**
 * This is a DocBlock for a function.
 */
function associatedFunction()
{
}

<?php
/**
 * I belong to a file
 */

/**
 * I belong to a class
 */
class Def
{
}

Tags and annotations:

 <?php
 /**
  * A summary informing the user what the associated element does.
  *
  * A *description*, that can span multiple lines, to go _in-depth_ into the details of this element
  * and to provide some background information or textual references.
  *
  * @param string $myArgument With a *description* of this argument, these may also
  *    span multiple lines.
  *
  * @return void
  */
  function myFunction($myArgument)
  {
  }

Source

Dave F
  • 1,837
  • 15
  • 20
Person
  • 1,091
  • 1
  • 9
  • 14
8

Use phpdoc (very similar to javadoc)

Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213
6

PHPdoc is the first thing that comes to mind, take a look at http://www.phpdoc.org/

bimbom22
  • 4,510
  • 2
  • 31
  • 46
3

PEAR (PHP Extension and Application Repository) has coding standards that includes a sample file using phpDocumentor, as well as some other useful conventions.

jwhitlock
  • 4,572
  • 4
  • 39
  • 49