Generate Constructor, Getters and Setters in NetBeans PHP IDE
Petr Pisl is the lead engineer of the PHP work scheduled for NetBeans IDE 6.5. Here he shares an update on some of the latest work that's been done in this area. -- Geertjan Wielenga, NetBeans Zone leader
This morning I have committed a feature to the NetBeans PHP support that will be part of NetBeans IDE 6.5, which offers generating of constructor, getters and setters in a PHP class. To invoke the functionality, the caret position has to be inside a PHP class and you have to press shortcut ALT+Insert (CTLRL+I on Mac). After invoking the shortcut, all possible generators are offered.
Let's explain on a simple example. I have very simple PHP class, where I have only two properties - $name and $age. At first I want to add constructor. After pressing ALT+Insert (CTLRL+I on Mac), the constructor generator is offered - Constructor... item in the Generate menu. After invoking this item, the Generate Constructor dialog is displayed. There I can choose parameters of the constructor. It is possible to chose any property, then the constructor is generated without any parameter and empty. If I check / uncheck the User class, then all properties are selected / unselected. For my demonstration I have chose $name property. After pressing OK button, the constructor with one parameter is generated.

Now I want to generate getter for the $name. After invoking Generate menu, you can notice that the Constructor... item is not offer anymore, because the class already has a constructor. I choose Getter... item and Generate Getters dialog is displayed. In the dialog you can choose, for which properties you want to generate getters. Again you can check / uncheck the class node, which selects / unselects all properties.

As the next step I want to generate getter and setter for $age property. After choosing Getter and Setter... item in Generate menu, the dialog offers only $age property, because only this property has neither getter nor setter.

When I invoke Generate menu after creating getter and setter for $age property, only setter generator is offered, because there is not defined only setter for $name property.

The generate functionality is designed that you can work just with the keyboard and you don't have to use mouse.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)




Comments
Piers Warmers replied on Mon, 2008/11/10 - 10:34pm
Arek Gel replied on Fri, 2008/11/21 - 9:13am
Hi, that's realy very nice, but is it possible to configure somehow naming template of getters/setters ?
I used to name my private class members with 'm_' prefix and first letter of object type, so then if I have $m_iAge and $m_sDriverName members, it would result in getM_iage() and getM_sdrivername() methods - their names are not too good ...
Best regards
Arek
Anthony Brophy replied on Fri, 2009/07/17 - 9:00pm
in response to:
Arek Gel
Matt Coleman replied on Thu, 2011/11/17 - 1:41am
in response to:
Anthony Brophy
me too...i am having problems with it too
website design buffalo
Ryan Fitz replied on Thu, 2011/11/17 - 2:17am
Gaston Quiroga replied on Sun, 2011/12/11 - 10:56am
Hi! I love this functionality. I've used it for java developing. But it doesn't work form me with php. The only options that show in the alt+ins menu are "Connection to Database" and "Database Table".
I'm using NetBeans IDE 7.0.1 (Build 201107282000)
I'll be glad if you can give me a solution.
Regards.
Gastón M. Quiroga.
/////////////EDIT///////////////////
Sorry! It works when the cursor is not over a propierty. My bad!
Matt Coleman replied on Fri, 2012/03/02 - 2:46am
it's all fixed now.thank God
graphic artist buffalo
Mateo Gomez replied on Fri, 2012/03/02 - 3:09am
best generator ever..thanks netbeans!
mexican salsa recipes
Carla Brian replied on Fri, 2012/03/30 - 5:44pm
Steve Sdas replied on Tue, 2012/09/25 - 8:05am
Steve Sdas replied on Tue, 2012/10/30 - 7:03am
Steve Sdas replied on Wed, 2012/10/31 - 5:12am
Steve Sdas replied on Sat, 2012/11/10 - 6:48am
Steve Sdas replied on Mon, 2012/11/12 - 12:40pm
Steve Sdas replied on Thu, 2012/11/15 - 6:01am
Steve Sdas replied on Thu, 2012/11/15 - 3:01pm
Steve Sdas replied on Sat, 2012/11/17 - 1:25pm
Steve Sdas replied on Sat, 2012/11/17 - 3:59pm
Steve Sdas replied on Sun, 2012/11/18 - 3:39am
Steve Sdas replied on Tue, 2012/11/20 - 12:41pm
Steve Sdas replied on Tue, 2012/11/20 - 2:39pm
Steve Sdas replied on Wed, 2012/11/21 - 10:31am
Steve Sdas replied on Mon, 2012/12/03 - 9:55am
Uilly Tocky replied on Tue, 2012/12/04 - 12:45pm
Uilly Tocky replied on Wed, 2012/12/05 - 5:58am
Uilly Tocky replied on Mon, 2012/12/10 - 3:21am
Uilly Tocky replied on Fri, 2012/12/14 - 3:48pm
Alex Jikic replied on Mon, 2012/12/17 - 7:37am
Thanks Petr. Really helpful info, tens unit .
Bryan Low replied on Tue, 2012/12/18 - 7:11am
Several vehicles are available near Woodlands EC along with purchasing and cafes. Woodlands EC is also near Causeway Element as well as Woodlands Beach. Entertainment for your near guests are therefore at your relaxation with the complete residence features as well as the services near Woodlands EC.
Uilly Tocky replied on Sun, 2012/12/23 - 10:17am