PHPDoc 0.2alpha
 
Author   Ulf Wendel <ulf@redsys.de>
Download phpdoc0.2alpha.zip (48kb)
 
What's this?

PHPDoc is an attempt to adopt Javadoc to the PHP world. PHPDoc does not have the power Javadoc offers, but it's quite useful to document your PHP source and always remember "this is alpha stuff".

PHPDoc is free (GPL). Nevertheless please do not distribute this version and even this URL. I don't want a public beta test, I'm not a friend of public alpha tests, I just need some feedback from a few guys. PHPDoc will become public, as soon as all major bugs are wiped out.

What about other PHPdoc Projects?

The name "phpdoc" is used for several other scripts and even for the PHP Documentation Team. Do not nix this script with one of them!

You probably heard of Goeran Zaengerlein's PHPDoc. We know each other and we're working together. One fine day PHPDoc will consist of two parts: PHPDog and PHPDoc. PHPDog provides a GUI that makes internationalization of the documentation easy an PHPDoc wich parses PHP source (not the C Source of PHP itself, but PHP Scripts!).

Installation

Installation is trivial. Download the Zipfile phpdoc0.2alpha.zip (48kb), extract it and place it somewhere on your webserver. Modify index.php3 or index.php4 to your needs and run them.

PHPDoc will extract the inline documentation from its source and write some HTML Files in the directory apidoc/. When it's finished and everything is fine it shows you a list of the generated files.

How can I test PHPDoc with my source?

I'm afraid to tell you, that I didn't spend much time in this yet. Currently you should modify the index.php[34] and use the given commands. PHPDoc is prepared to handle command line requests (core/PhpdocArgvHandler.php) but the code is untested and not up to date.

Note that PHPDoc only works on classes. A classname must be unique withing the given files.

How to write Inline Documentation

If you don't know Javadoc, please read the instructions given by Sun How to write Javadoc comments. I will give you only a brief overview on the features that I adopted to PHPDoc. Within the instructions I'll always give some notes on how it is realized in the source code and which part of PHPDoc does this job.

What does a documentation comment look like?

A documentation comment is multiple line comment starting with "/**" (two asterix) and ending with "*/". All subsequent lines start with "*". On the top of a documentation comment is the description. The first line is called "shortdesc" in the PHPDoc source and shown in summaries. All following lines before the comment ends of a tag appears, are called "$fulldescription"/"desc". This "desc" is only showed in the detail view of a variable, method or class.
Source: parser/PhpdocParserObject->getPhpdocParagraphs()

 
/**
* Short description - first line, always shown in an overview table
* 
* Full description, not shown in an overview table, just in the detail 
* view. Descriptions may contain <b>HTML</b> Tags.
* The description ends where the 
*/

Documentation comments are only recognized when they're followed by a certain keyword. PHPDoc uses a combination of regular expressions (preg.*) and strpos() to find the keywords.
Source: parser/PhpdocParserObject, all PhpdocXYParser->addUndocumentedXY()

  var
  function
  class

Tags?

PHPDoc tags look very much like Javadoc tags. They start with "@" followed by the tagname and the "tagvalue". Currently PHPDoc knowns ten tags:

  @abstract
  @access
  @author
  @brother
  @copyright
  @param
  @return
  @see
  @since
  @static
  @throws
  @var
  @version

Source: parser/PhpdocParserObject->getTags(), parser/PhpdocParserObject->PHPDOC_TAGS

In constrast to Java you're currently not allowed to embed tags in the leading description paragraph of a documentation comment. There's no technical reason to do so; I simply preferred it that way, it makes reading the source a little easier.

As with documentation comments not every tag is allowed everywhere. It simply makes no sense to use @param in a class comment... He're what's recognized with a certian keyword:

  keyword class:
  • @author
  • @copyright
  • @since
  • @version
  • @static
  • @abstract
  keyword function:
  • @param
  • @return
  • @throws
  • @see
  • @brother
  • @abstract
  • @static
  • @version
  • @since
  • @author
  • @copyright
  keyword var:
  • @var
  • @access
  • @see
  • @since
  • @version
  • @abstract
  • @static

Today there're no rules in which order you should write the tags in your comments. I suggest to take the order shown in the table above.

Limitations

One of the worst things on PHPDoc is, that it does not compare the PHP Source with your doc comment. This has some nasty side effects, e.g. the @param tag request you to specify the variable name which is only a few lines below in the PHP Source...

Tag Quick Ref

I'll just write a few lines on common tags. Please have it look at the Source to find out more on the syntax. Have an intensive look on parser/PhpdocParserObject. There're many regular expressions that get used when analysing tags.

@abstract

  1. @abstract
Note: No values allowed.

@access

  1. @access private
  2. @access public
Note: If avoided "private" is assumed (except for public constructors).

@author

  1. @author Name [<email>]
  2. @author Name [<email>] [, Name [<email>]]

@brother

  1. @brother functionname
Sometimes you have functions that do nearly the same. One returns a specific value and the other one if the print version of the other one. E.g. getWarnings() returns and array of warnings and printWarnings() prints them. printWarnings() calls his "brother" getWarnings() to to so. Now you can tell phpdoc to take most the documentation from getWarning() and override certain parts.

@copyright

  1. @copyright Name [<email>]
  2. @copyright Name [<email>] [, Name [<email>]]

@param

  1. @param vartype $varname description
  2. @param object objectname $varname description
Note: If avoided "void" is assumed. There's no notation for optional parameters, parameters with predefined values or functions with variable argument numbers.

@return

  1. @return vartype $suggested_varname description
  2. @return object objectname $suggested_varname description
Note: If voided "void" is assumed.

@see

  1. @see varname
  2. @see functionname()
  3. @see funtionname() [,varname]
Note: You can't referr to other classes yet. Links to inherited variables and functions() are recognized.

@static

  1. @static
Note: No values allowed.

@since

  1. @since free value

@throws

  1. @throws name of exception [, name of another exception]
Note: Experimental as long as PHP doen't support throw...

@var

  1. @var vartype $varname description
  2. @var object objectname $varname description
Note: There's no notation for default values.

@version

  1. @version free value

Contact

You can contact me by email ulf@redsys.de or give me a call: +49 431 66 13 304. Mostly you'll meet me at home in the evening from 8-10pm.