PHPDocumentor 0.4.1

Joshua Eichorn <jeichorn@phpdoc.org>
Gregory Beaver <cellog@sourceforge.com>

PHPDocumentor is the most advanced automatic documentation system written for PHP, in PHP. This package has many features:

Note: if this howto looks bad, get a browser that supports css

PHPDocumentor basics

The documentation process begins with the most basic element of PHPDocumentor: a Documentation block or DocBlock. A basic DocBlock looks like this:


/**
*
*/

A DocBlock is an extended C++-style PHP comment that begins with "/**" and has an "*" at the beginning of every line. DocBlocks precede the element they are documenting. To document function "foo()", type:


/**
* Defies imagination, extends boundaries and saves the world ...all before breakfast!
*/
function foo()
{
}

define() statements, functions, classes, class methods, and class vars can all be documented.

A DocBlock contains three basic segments in this order:

The Short Description is on the first line, and can be terminated with a period or with a blank line. The Long Description continues for as many lines as desired and may contain html markup for display formatting. Here is a sample DocBlock with a Short and a Long Description:

/**
* return the date of Easter
* 
* Using the formula from "Formulas that are way too complicated for anyone to 
* ever understand except for me" by Irwin Nerdy, this function calculates the 
* date of Easter given a date in the Ancient Mayan Calendar, if you can also
* guess the birthday of the author.
*/

Tags

Tags are single words prefixed by a "@" symbol. Tags inform PHPDocumentor how to present information and modify display of documentation. All tags are optional, but if you use a tag, they do have specific requirements to parse properly.

A sample DocBlock showing all possible tags

More tags may be added in the future, not all tags are implemented at this time in phpdocumentor, however they are all recognized as tags and will at least be displayed


/**
* The short description
*
* As many lines of extendend description as you want {@link element} links to an element
* {@link http://www.example.com Example hyperlink inline link} links to a website
* Below this goes the tags to further describe element you are documenting
*
* @param  	type	$varname	description
* @return 	type	description
* @access 	public or private
* @author 	author name 
* @copyright	name date
* @version	version
* @see		name of another element that can be documented, produces a link to it in the documentation
* @link		a url
* @since  	a version or a date
* @deprecated	description
* @deprec	alias for deprecated
* @magic	phpdoc.de compatibility
* @todo		phpdoc.de compatibility
* @exception	Javadoc-compatible, use as needed
* @throws  	Javadoc-compatible, use as needed
* @var		type	a data type for a class variable
* @package	package name
* @subpackage	sub package name, groupings inside of a project
*/

Tag Information:

Inline Tag Information:
Inline tags are formatted like: {@tag params}, where "tag" is the name of the inline tag and params is parameters for the inline tag. Inline tags display their output in the normal flow of the text, and should be used in descriptive areas of the DocBlock.

Elements that can be documented

Every major reusable element in PHP can be documented:

Packages are collections of elements into a group for documentation and release purposes. They may contain any of the standard PHPDocumentor elements (class, function, class method, class variable, define). A Package-level doc is an html file with the same name as the package that is located in the same directory as one of the physical files that contains a package element. In other words, for package foo that contains class bar in file /php/bar.php, PHPDocumentor will attempt to document "foo.html" by looking for /php/foo.html.

Package-level docs should be in standard html format. The only valid tags in Package-level documentation are inline tags. For this release, that means ONLY {@link} may be used in package-level documentation

Here is some example package-level documentation for package baz that contains classes fooclass and barclass


<html>
<head>
	<title>Package baz>/title>
</head>

<body>
This package is essential.  using class {@link fooclass} you can instruct your computer to brush your teeth for you.  Combining this functionality with the back massage given by {@link barclass}, you may truly retire in comfort.  In particular, {@link barclass::footmassage()} is a most exquisite experience.
Please follow this list of links for more help:
<ul>
	<li><a href="http://www.microsoft.com/support"><The reinstall Windows hotline>
	<li><a href="http://www.php.net"><Heaven>
	<li><a href="http://phpdocu.sourceforge.net"><The PHPDocumentor Homepage>
	<li><a href="http://www.chiaraquartet.net"><The most beautiful music you've ever heard>
</ul>


</body>
</html>

Procedural Pages are physical files that contain at least one function or constant. They may also contain classes, but every class is documented separately from the physical file that contains it. In other words, if foo.php contains function bar() and class baz, bar will be documented as part of Procedural Page _foo_php, and class baz will be documented as class baz. PHPDocumentor interprets the first DocBlock in a file as a Procedural Page-Level DocBlock, or page-level DocBlock, if and ONLY if it does not precede any elements before the next DocBlock.


/**
* Page-level DocBlock
*
* This procedural page contains many functions that blah blah blah
*/
/**
* function or define DocBlock
*/
function blah()
{
...
}

The following is an example of a NON-page-level DocBlock


/**
* Almost a Page-level DocBlock
*
* This procedural page contains many functions that blah blah blah
*/
define("screwedup",66);
/**
* function or define DocBlock
*/
function blah()
{
...
}

PHPDocumentor will interpret the first DocBlock as belonging to define("screwedup",66), rather than to the page

All other elements are documented by placing the DocBlock before the element. Any valid PHP Code may be placed between a DocBlock and an element as long as it isn't another element.


/**
* DocBlock will document function blah()
*/
// random comment
$a += strpos(get_another_thingy(66,$ufta));
$ark->build($a);
// etc. etc.
function blah()
{
...
}

A realistic example

The code below is a sample class showing PHPDocumentor in action

PHPDocumentor can parse any valid PHP code, but it is recommended to follow this style for ease of programming for both you and people who will be using your packages


/**
* A sample class
*
* This class is just random php used as a {@link http://phpdocu.sourceforge.net phpdoc} example
*
* @version 1.0
* @author Joshua Eichorn <jeichorn@phpdoc.org>
* @project test
*/
class phptestclass
{
	/**
	* A sample class variable
	* @access private
	* @var string
	*/
	var $sample;

	/**
	* The class constructor
	*
	* This sets up the class and does other random stuff
	*/
	function phptestclass
	{
		$this->sample = "test";
	}

	/**
	* A test function
	*
	* This function returns {@link $sample}
	*
	* @see set(), $sample
	* @return string
	*/
	function test()
	{
		return $this->sample;
	}

	/**
	* Set the sample var
	*
	* @param string $var
	* @see phptestclass::$sample, phptestclass::test()
	*/
	function set($var)
	{
		$this->sample = $var;
	}
}