Generate getter/setter for PHP Classes in Eclipse

| By Webner

Using PHPGen Eclipse plug-in one can automatically generate getter /setter methods for instance variables.

Note: This Plugins is not available in Eclipse Marketplace.

Steps For Installation:

Start Eclipse and add “Help> Install New Software” from following URL:

Click Add, enter in both the text boxes and on confirm you will see PHPGen available for installation.

Uncheck “Group items by Category” and check the checkbox of PHPGen a proceed. “Calculating Requirements and Dependencies” may take several minutes but the plugin will be installed successfully. Restart Eclipse. After the restart, a new menu item “Generate” is visible:

How to use it:

Open any PHP file with a class in it, for example:

class Vegetable
 private  $edible;
 private  $color;
 function Vegetable($edible, $color="green")
   $this->edible = $edible;
   $this->color = $color;

Click on “Generate” in a menu bar (Generate> PHP getters/setters…), check fields and required methods and click “Generate”. The getter/setter methods are automatically inserted at the end of the class:

Leave a Reply

Your email address will not be published. Required fields are marked *