Generating Getters and Setters Improved

Today I have committed to the trunk small improvement of generating getters and setters for class properties. It's based on your suggestion and as you can see on the pictures, you can select the way, how to generate the getter and setter method name.

There is a new combo box that contains two items which display the result of the method name for the first class field. On the picture you can see that you can select between two ways. The first one is the way which is used in NetBeans 6.5 and the second one is with underscore between get/set and property name.

There is the first question: Does somebody use different form of the getter and setter name? If yes, please speak up and I will update the dialog.

The enhancement is not fully finished. The value of the combo box now is not remembered, but I will add functionality, which will remember it per project. So the second question is: Do you use different form of getter and setter method names in different projects? Or you use just one way? Should be project or global options?

When I tested the enhancement then I have thinking to add also option for generating Php doc stub. But I haven't time to finish it yet.


Look at Eclipse. It has very flexible configuration for getters/setters generator per project. I like it. I can use private properties with some prefix, e.g. private _name; or protected m_name. I configure Eclipse to identify those prefixes, so the getters/setters are always the same, setName() or set_name(), etc.

Posted by jozef on November 10, 2008 at 07:06 AM CET #

I normally have variables in the form of myVar, and use getters and setters in the form of getVar and setVar.

Posted by chad on November 10, 2008 at 05:43 PM CET #

Hello, Petr.
I want to know if there is a funciton that can select and complete a path when a input a file or folder path to the file. just like the code completion popup. Some times I always forget the real path name. If there is, it will do me good help to write my program

Posted by fortruth on November 10, 2008 at 06:53 PM CET #

Hi Fortruth,

I'm not sure if I understand correctly, but there is file system code completion for include and required functions. Also for finding a file you can use Navigation -> Go To File dialog. Could you describe the case, where you need it?


Posted by Petr on November 11, 2008 at 06:38 AM CET #

Hi! Any news on the framework support?
Congratulations on the great work you are doing!
Thanks, Joaquín

Posted by Joaquin Fernandez Campo on November 12, 2008 at 02:04 AM CET #

Hi Joaquin,

I plan this weekend a little work on the Prado support and officially we are starting on Symfony support.


Posted by Joaquin on November 13, 2008 at 08:05 AM CET #

Sorry for my bad English.

I use setters & getters with magic methods __get __set is very easy to work with this functions...

Posted by Jaime M. Tan on November 18, 2008 at 09:49 AM CET #

It would be nice if the IDE was, at some point, able to generate skeleton magic __get/__set methods for classes based on the define PHPDOc @property tags.

A basic example of a __get method would be:

public function __get($strName) {
switch ($strName) {
case 'strA': return $this->strA;
case 'intB': return $this->intB;
return parent::__get($strName);

A basic example of __set would be:

public function __set($strName, $mixValue) {
switch ($strName) {
case 'strA':
$this->strA = $mixValue;
return true;
return parent::__set($strName, $mixValue);

Posted by Adam Jorgensen on November 20, 2008 at 05:27 AM CET #

Hi Adam,

good idea. Simple to implement. I will try to do it. Could you file enhancement in our Issuezilla? ( , component PHP, subcomponent editor)?


Posted by Petr on November 20, 2008 at 06:18 AM CET #


For field "fileName" generate getter with name "getFilename" not "getFileName".

Posted by Marat Fedorov on December 08, 2008 at 10:32 AM CET #

If I had:

private $myVar;

I would expect the name of the getter/setter to be:

public getMyVar();
public setMyVar();

Currently it seems to only do getMyvar and setMyvar

Posted by Blake on December 10, 2008 at 01:19 AM CET #

To Marat, Blake: You are right. This is a bug. I will fix this. ( )


Posted by Petr on December 10, 2008 at 09:31 AM CET #

Hi! Very good this feature!

My code standard is based in

SetName() and GetName()


Posted by Michel Filipe on December 16, 2008 at 06:12 AM CET #

Thanks to Michel for the link.

Posted by Petr on December 16, 2008 at 04:06 PM CET #


it's very good but maybe u should use some template not select, for example set_%name% for set_something and for SetSomething Set%Name%, etc. Then everyone can choose option that is good for him. In this solution it's impossible.

Posted by Krystian kuczek on January 19, 2009 at 08:08 AM CET #

Hi Krystian,

you are right this is the best solution and it should be done in this way. On the other hand it cost some resources, which are not available now. So we will see and I hope that we will find more time to finish this feature in this way.

Posted by Petr on January 19, 2009 at 01:59 PM CET #

Thank for this nice article!

Posted by Ankara Bilgisayar Bilgisayar Satis on February 03, 2009 at 08:47 AM CET #

I prefere another style for protected variables. $_name for example. "_" at the beginning means "private" or "protected" for me.
I would like to have getName() getter for $_name variable


Posted by alexey_baranov on February 04, 2009 at 06:24 AM CET #

thanks very nice

Posted by chat on March 08, 2009 at 06:42 AM CET #


Posted by kelebek on April 26, 2009 at 04:57 AM CEST #

Please support $_variableName style variables for Getters and Setters.

Web have been migrating our site from cold fusion to PHP over the past few months. Initially, we started using Eclipse PDT, but when we found that it doesn't support refactoring or generating of Getters and Setters and custom formatting, I decided to explore NetBeans which I had only previously used for Java. I have to say I am very very impressed with the full featured offerings I found. I've decided to make it my primary IDE for PHP rather than going for the Zend Studio, except I have one snag. when I generate getters and setters from class variables of the $_variableName style (which is our site-wide convention) I get methods like this: "get_variablename()" and my camel casing is removed and it leaves my underscore. Our standard getter and setter syntax is getVariableName().

Would it be possible to add this to the drop down list of options? Thank you.

Also, I do appreciate the added support for php code formatting options in the 6.7 beta release as far as the option to put the curly brace below the first line (also one of our conventions). Is there any more planned support for other formatting options such as those for for loops, if/else/switch statements. We have a lot of coding conventions enforced on our team and it would be great to have these types of options to speed up the work.

Thank you very much.

Posted by Dustin Graham on May 29, 2009 at 05:10 PM CEST #

Hi, it would be great if next version includes support to $_variableName in the form of getVariableName() setVariableName().

As many other people i use it to name protected and private members.


Posted by patchinko on July 28, 2009 at 03:12 PM CEST #

thanks admin

Posted by konya chat on August 20, 2009 at 10:31 AM CEST #

Hi, I agree. Now that 6.9 supports Zend Framework which uses underscore prefixes for private/protected class variables, supporting this would be extremely helpful


Posted by rodp on May 24, 2010 at 02:05 AM CEST #

Agreed, I'm crying out for $_variable Getter / Setter support!

Thanks for the great prduct.


Posted by Ben Waine on August 11, 2010 at 10:12 AM CEST #

Thank you, this is great functionality.

I have a question however.
I am trying to make Netbeans the only tool used in development and have development done as fast as possible. Based on database / table structure I would like to generate a class in PHP. Could you give me some guidance on how to tackle this problem? Is this alt-insert functionality hardcoded into netbeans or is this kind of module I could customize/extend somehow?

Thank you for your answer.

Best regards

Posted by norbi771 on September 06, 2010 at 08:14 AM CEST #

To Norbert:

the alt-inert functionality is really hartcoded, but you can write your own plugin that will add new item there and generate what you want. What exactly do you want?


Posted by Petr Pisl on September 08, 2010 at 08:08 AM CEST #

To Petr Pisl:

Thank you for your answer. I am very new to java and although I fully understand the semantics and can read the code without problems with understanding it, I have no experience in Java coding at all. Tried a bit but no hurahh ... yet. I thought that maybe getter/setter and Database Table generators were based on some kind of template I could simply adjust but you confirmed they were not.
However, in netbeans sources I found code responsible for generating getter/setter and Database table. These modules are very good examples for my case.
Following your advice I will try write netbeans module doing what I want, thank you.


Posted by norbi771 on September 09, 2010 at 03:41 AM CEST #

To Norbert: Some times you need some information from source model. Like in getter / setter example we check, whether there is not a method with the same name. This is reason why you need to do it in java. In your case, you will need information from database model.


Posted by Petr Pisl on September 09, 2010 at 09:50 AM CEST #

I'm using this great feature all the time - but i always have to correct each generated function by hand, as my classes normally implement the fluent interface (which means all setters end returning $this) and my coding standards require a newline b4 an opening brace.

Is there any way for me of editing the "template" that is used for function generation? Anyway i think adding e.g. an option checkbox to generate fluid interface setters would be an awesome feature - i simply cannot be the only programmer out there preferring his/her setter fluid ;)

Posted by guest on May 02, 2012 at 11:57 PM CEST #

Hi, there is an enhancement in our issuezilla for this feature. I would like to look at it for next release.

Posted by Ondrej Brejla on May 09, 2012 at 09:25 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blogs is written by NetBeans developers who contribute to the PHP support mainly.


« February 2017