preload preload

Generate PHP Documentation in Netbeans [Windows]

Netbeans for PHP is a wonderful IDE and it is continuously becoming favorite among the PHP developers. Carrying tons of features for PHP development it is a breeze to work with it and develop simple and large PHP application development.

If you are a good developer, you might know that for a project it is always very important to create the API documentation, so that if somebody else is looking on your code, atleast he can understand it fast. PHP supports documentation tags (with annotations) in the source code and then using simple utilities we can generate the API documentation quickly.

Now as we know that Netbeans does not have native support for generating documentation, but we can use a workaround to do that. This post will guide you about how to generate PHP documentation for a PHP project created in Netbeans in Windows OS.

Introduction to PhpDocumentor

To generate documentation, we require some utility. PhpDocumentor is a simple documentation tool which extract the documentation tags from the PHP source code and generate the API documentation. There are lots of features available with it which can be found here

Installing PhpDocumentor on Windows

We can easily install PhpDocumentor on Windows using PEAR utility. Following is the command to install PhpDocumentor with pear

pear install PhpDocumentor

After installation of PhpDocumentor on windows, there is batch file phpdoc.bat created in PEAR folder on your system. In my case it was created in C:\Apache2\php\PEAR\ folder. We will utilize this batch file in Netbeans to generate our API documentation.

Integration PhpDocumentor with Netbeans

Before we start with integration, we are required to create a batch file which will inturn call the phpdoc.bat to generate PHP documentation.

In your php folder, create a batch file phpdocnb.bat (in my case it is in C:\Apache2\php\phpdocnb.bat) and put the following content in to it.

C:\Apache2\php\PEAR\phpdoc -d %2 -t %3
echo "Generating PHP Documentation finished ..."

-d specifies the directory which contains all the PHP files for which we need to generate the documentation.

-t specifies the storage path to the generated documentation

%2 and %3 specifies the folder parameters which we will provide.

Configuring Netbeans for PhpDocumentor

Follow the steps mentioned below to run PhpDocumentor from Netbeans

1. Right click on the project directory or goto File->Project Properties to open the Project Properties Dialogue box as shown in the attached image

Netbeans Project Properties menu

Netbeans Project Properties menu

2. On the Project Properties Dialogue box, select Run Configuration and enter the settings as shown below:

a. Configuration: Give your configuration name as “PHPDoc”

b. Run As: Select “Script(run in command line)”

c. Uncheck “Use Default PHP Interpretor” and Browse to “phpdocnb.bat” file.

d. Arguments: This section is important. Provide two arguments separated by space. The first argument is path to your PHP source directory. The second argument is path to folder where you want to store your PHP documentation.

e. Click “Ok”

Netbeans Project Properties

Netbeans Project Properties

3. Now you are all set. Just click on the Run->Run from the menu or Press F6 to generate your PHP documentation.

Hope you enjoyed the post.


Liked the content? Then why not share with your pals

  • 4 responses to "Generate PHP Documentation in Netbeans [Windows]"

  • Chris Ward
    5:45 on April 23rd, 2011

    Hi thanks for the tutorial, i’m getting the following error though

    ‘C:\xampp\php\PEAR\PHPDoc’ is not recognized as an internal or external command,
    operable program or batch file.

    any ideas why? the echo statement is working from the .bat file but no docs are being created

  • Deepesh
    8:28 on May 4th, 2011

    Did you installed PHPDocumentor from PEAR? If yes what is the location?

  • menuka
    19:07 on October 2nd, 2011

    I get the following error
    ERROR: failed to mkdir .\pear\data\PhpDocumentor\docbuilder\images

  • Deepesh
    20:45 on October 3rd, 2011

    @menuka, check whether the path mentioned by you is existing on your box or not. If any of the parent dir is missing, it will throw this error

  • Leave a Reply

    * Required
    ** Your Email is never shared