Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Create nice documentation for your PHP code

Tuesday, April 3rd, 2018 by Servage

It’s a common problem amongh developers that insufficiently or no documentation of code causes problems, delays, misunderstandings. Even code you wrote yourself could look really strange after a while, when you no longer remember what’s exactly going on. At this point a good documentation could help you save time and nerves.

PhpDocumentor is a good script that generates documentation for your code based on inline comments in your script files. It can generate various output formats, has different themes, and is very customizable. It only requires that you actually commend your code.

You can read how to comment your code easily in the PhpDocumentor manual. There are a few useful samples and general descriptions of all tags etc. you can use in your code.

The actual usage of PhpDocumentor is really simple. You just need to download the package, place it somewhere accessible via a browser, and you get a nice webinterface to create your documentation. Remember that PhpDocumentor needs proper read/write permissions to your project files and the documentation destination folder, where you docs are stored. It’s all described in the PhpDocumentor manuel, and you should be able to have a finished documentation of your project within just a few minutes (plus the time to actually write the needed comments). As time passes you will hopefully learn to comment your code as you write it, so the generation of the documentation becomes a continous, easy and natural part of your development. I’m sure this will ease your work!

Sample commented class

/**
 * My class
 * Provides my own functions for my own purpose. Really cool!
 * @package mystuff
 */
class MyClass {
    /**
     * @var string $myvar The most important variable.
     */
    var $secondvar = 42;
    
    /**
     * Function that does something.
     * @param string $what to do.
     * @return boolean true if it could be done, false if no.
     */
    function doSomething($what) {
      return true;
    }
}

Create nice documentation for your PHP code, 4.9 out of 5 based on 7 ratings
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 comment (leave a comment)

documentation we will be requiring that your code be fully documented.

Leave a comment

You must be logged in to post a comment.