NetBeans PHP Comments

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

Comments your code are essential to help both other developers and, in some cases, yourself understand what the code is meant to be doing.

When developing PHP in NetBeans there are two types of comments to consider. The first type of comments are the normal type of comments that are for a human to read and understand. This type of comments will say thing like “// This section is here to…” and “// This is necessary because…”. While human readable are definitely good, one of the issues when developing PHP is that it is difficult for IDEs to maintain the type of variables, the return types of methods and the type of variables that a method excepts. This is mainly because PHP is loosely typed but also because IDEs often can’t follow the inheritance hierarchy for what ever reason.

To get around the issues of type hierarchy and PHP been a loosely typed language, NetBeans supports type definition comments. This type of comment is intended to help the user of the IDE know what type a variable should be and also what types of variables a method expects and allow auto completion to function.

Example: /** * Remove item from cart * * @param int $itemId This is the id of the item to remove * @return Mage_Checkout_Model_Cart */ public function removeItem($itemId) { $this->getQuote()->removeItem($itemId); return $this; } This example lets NetBeans know that removeItem’s one parameter should be an integer and that it returns an object of type Mage_Checkout_Model_Cart. Image

The other type of type comment tells NetBeans that a particular variable is of a specific type. For example: class RemeberNumber {

/** @var $theNumber int */
protected $theNumber;

public function __construct($number) {
    $this->theNumber = $number;


Because of the /** @var $theNumber int */ auto completion will now use that as the type else where with in the scope of that variable definition.


Tags: phpnetbeansautocompleteidecommentscoading