phpDocumentor 1.1.0

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

Primary phpDocumentor Documentation

phpDocumentor HOWTO written by Gregory Beaver and Joshua Eichorn
Copyright © 2002, Gregory Beaver, Joshua Eichorn

Table of Contents

Introduction
Basics
DocBlock Tags
Inline Tags
Documentable PHP elements
A Simple Example
phpDocumentor command-line switches
phpDocumentor web interface notes

Introduction

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. NOTE: Any line within a DocBlock that doesn't begin with a * will be ignored. 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 starts on the first line, and can be terminated with a blank line or a period. A period inside a word (like example.com or 0.1 %) is ignored. If the Short Description would become more than three lines long, only the first line is taken. 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. The inline
* source tag displays function source code in the description:
* {@source}
* 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 <author@email>
* @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
* @global	type	$globalvarname
  or
* @global	type	description of global variable usage in a function
* @staticvar	type	description of static variable usage in a function
* @name		procpagealias
  or
* @name		$globalvaralias
* @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
*/
function if_there_is_an_inline_source_tag_this_must_be_a_function()
{
...
}

Tag Information:

Inline Tags

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 used to help you logically group related elements. You write classes to group related functions and data together, and phpDocumentor represents the contents of files (functions, defines, and includes) as "Procedural Pages." A package is used to group classes and procedural pages together in the same manner that a directory groups related files together. A Package-level doc is an html file that documents general things about an entire package. It has the name "package.html" where package is the name of the package. 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 the same directory as any file that contains a page-level or class-level @package tag

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 any physical files that phpDocumentor documents. They may contain any documentable element, or nothing at all, but should contain at least a page-level DocBlock to be of any use for the end-user. phpDocumentor documents all includes, defines, and functions found in the file, and links to documentation for classes defined in the file, 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

Global Variables can only be documented by using the @global tag in a DocBlock preceding the global variable's definition. See the manual for @global for detailed information on how to use @global to document your project's global variables.

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 Simple 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 page-level DocBlock
* The package tag applies to all global variables, functions, defines and includes in this page
* @package pagetest
*/
/**
* A sample global variable
* @global array $GLOBALS['sample']
* @name $sample
*/
$GLOBALS['sample'] = array('1',2,"3","4" => 5);
/**
* A sample class
*
* This class is just random php used as a {@link http://phpdocu.sourceforge.net phpdoc} example.
* To see the $sample variable, you must use the command-line option --parseprivate or click the
* box in the web interface
*
* @version 1.0
* @author Joshua Eichorn <jeichorn@phpdoc.org>
* @package test
*/
class phptestclass
{
	/**
	* not parsed unless you use -pp on
	* @access private
	*/
	var $privatevar;
	/**
	* A sample class variable
	* @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
	* @global array used to get some sample stuff
	* @return string
	*/
	function test()
	{
		global $sample;
		return $sample == $this->sample;
	}

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

/**
* This function is in the page package, which is "pagetest" and not "ignored"
*
* this @package tag is ignored - only the page-level tag is parsed.
* @staticvar phptestclass an example of our static documentation
* @package ignored
*/
function inPagePackage()
{
	static $mememe;
	$mememe = new phptestclass;
}

phpDocumentor command-line switches

From the README:

You can have multiple directories and multiple files, as well as a combination of both options

if you run phpdoc and get :
bash: ./phpdoc: No such file or directory

Then you haven't installed the cgi version of php
goto your php src dir and try
make clean
./configure
make
make install

phpdoc should work now

If your usinging php 4.2.0 or higher you might want to make the cli version
instead of the cgi. Checkout php.net for details on these changes

Command-line switches
-o--outputoutput information, format:converter:template (HTML:default:DOM\l0l33t for example)
-ct--customtagscomma-separated list of non-standard @tags to pass to the converter as valid tags
-d--directoryname of a directory(s) to parse directory1,directory2
-dh--hiddenset equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off
-dn--defaultpackagenamename to use for the default package. If not specified, uses 'default'
-f--filenamename of file(s) to parse ',' file1,file2. Can contain complete path and * ? wildcards
-i--ignorefile(s) that will be ignored, multiple separated by ','. Wildcards * and ? are ok
-q--quietdo not be verbose
-pp--parseprivateparse elements marked private with @access. Use on/off, default off
-po--packageoutputoutput documentation only for selected packages. Use a comma-delimited list
-t--targetpath where to save the generated files
-ti--titletitle of generated documentation, default is 'Generated Documentation'
-j--javadocdescuse JavaDoc-compliant description (short desc is part of description, and is everything up to first .)

phpDocumentor web interface notes

From the README:

Put phpdoc.php together with the *.inc files someplace on your webserver where it can read them. NEVER USE THE WEB INTERFACE ON A PRODUCTION WEBSERVER. Allowing your server to write files to disk is a serious security risk, and phpDocumentor is not designed to work on non-secure systems. Setup php on a development machine and run phpDocumentor from there. Make sure you webserver can write to where ever you specify as a target or you will get lots of errors