PHP
  Home arrow PHP arrow Page 3 - Writing Self-Documenting PHP Code
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Writing Self-Documenting PHP Code
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2002-04-15


    Table of Contents:
  • Writing Self-Documenting PHP Code
  • Speaking In Tongues
  • Drilling Deeper
  • I, Robot
  • Tonight's Menu
  • Different Strokes
  • Closing Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Writing Self-Documenting PHP Code - Drilling Deeper
    ( Page 3 of 7 )

    As you can see from the example on the previous page, a general overview of the class is provided in the comment block preceding the class definition.


    <?php /** * Automatically creates a sandwich customized to your preferences * * @author Melonfire <melonfire@mail.com> * @version 2.0 * @since 1.3 * @access public * @copyright Melonfire * */ class SandwichMaker() { // snip } ?>
    The first line within the comment block provides a brief, human-readable description of the class. It is followed by a blank line, and a series of tags.

    Each of the tags in the comment block above provides information on some aspect of the class. Here's a brief list of what they represent:

    @author - the name of the class author

    @version - the current version number of the class

    @since - historical information on the availability of this class

    @access - whether this class is a private or public class

    @copyright - the name of the copyright holder of the class

    Most of these tags are optional; PHPDoc will either use default values if they are not present, or simply ignore their absence.

    If a class has multiple authors, you may list them using multiple @author tags - remember to group them together so that the parser has no difficulty finding all of them.

    If you would like to group your classes together, you can also use the

    @package package-name
    tag as a grouping key; PHPDoc will then use the package name to group all related classes together when creating the documentation.

    Moving on, once the class has been documented, the next step is to document the class variables. Here's an example:

    <?php /** * Bread type * * @var integer * @access public * @see setType() */ var $type; ?>
    In addition to the tags described above, class variables can have two additional tags, both of which are fairly self-explanatory:

    @var - the variable type

    @see - references to other, related variables and methods

    Finally, all that's left is to document the class methods. Here's a quick example,

    <?php /** * Sets bread type for sandwich * * @param integer $type bread type * @return Boolean * @access public * @see makeSandwich() * @see setFillings() */ function setType($type) { // snip } ?>
    Class methods can use two additional tags, in addition to the ones previously described:

    @return - a description of the return value from the method

    @param - a description of the argument passed to the method, in the form


    @param arg-type arg-name arg-description
    Obviously, you should include as many @param tags as there are arguments to be passed to the method, and you should make it a point to list them in the order in which the method expects them.

    It should be noted that the @see tag is particularly useful when it comes to documenting class methods - it provides an easy way to create connections between related methods. PHPDoc will automatically hyperlink the methods named in the @see tag to each other when it creates the documentation.

     
     
    >>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek