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 03:06 PM 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 11, 2008 at 01:43 AM 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 11, 2008 at 02:53 AM 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?
Regards,
Petr
Posted by Petr on November 11, 2008 at 02:38 PM 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 10:04 AM CET #
Hi Joaquin,
I plan this weekend a little work on the Prado support and officially we are starting on Symfony support.
Regards,
Petr
Posted by Joaquin on November 13, 2008 at 04:05 PM 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 05:49 PM 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;
default:
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;
default:
return parent::__set($strName, $mixValue);
}
}
Posted by Adam Jorgensen on November 20, 2008 at 01:27 PM CET #
Hi Adam,
good idea. Simple to implement. I will try to do it. Could you file enhancement in our Issuezilla? ( http://www.netbeans.org/community/issues.html , component PHP, subcomponent editor)?
Thanks,
Petr
Posted by Petr on November 20, 2008 at 02:18 PM CET #
Hi
For field "fileName" generate getter with name "getFilename" not "getFileName".
Posted by Marat Fedorov on December 08, 2008 at 06:32 PM 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 09:19 AM CET #
To Marat, Blake: You are right. This is a bug. I will fix this. ( http://www.netbeans.org/issues/show_bug.cgi?id=155158 )
Thanks,
Petr
Posted by Petr on December 10, 2008 at 05:31 PM CET #
Hi! Very good this feature!
My code standard is based in http://www.dagbladet.no/development/phpcodingstandard/.
Example:
SetName() and GetName()
Bye!
Posted by Michel Filipe on December 16, 2008 at 02:12 PM CET #
Thanks to Michel for the link.
Posted by Petr on December 17, 2008 at 12:06 AM CET #
Hi.
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 04:08 PM 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 09:59 PM CET #
Thank for this nice article!
Posted by Ankara Bilgisayar Bilgisayar Satis on February 03, 2009 at 04:47 PM 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
Thanks.
Posted by alexey_baranov on February 04, 2009 at 02:24 PM CET #
thanks very nice
Posted by chat on March 08, 2009 at 01:42 PM CET #
thanks..
Posted by kelebek on April 26, 2009 at 11: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 30, 2009 at 12:10 AM 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.
Thx!
Posted by patchinko on July 28, 2009 at 10:12 PM CEST #
thanks admin
Posted by konya chat on August 20, 2009 at 05:31 PM CEST #
<a href="http://www.gaylez.org" title="gabile" target="_blank">gabile</a>
Posted by Gabile on September 29, 2009 at 08:40 PM CEST #
thanks admin
Posted by konya chat on October 18, 2009 at 05:26 PM CEST #
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
Posted by links of london on October 31, 2009 at 03:35 AM CET #