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.
From: http://blogs.sun.com/netbeansphp
- Login or register to post comments
- 7209 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
warmers replied on Mon, 2008/11/10 - 10:34pm
afoka 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
Gramesmith1 replied on Mon, 2009/05/18 - 12:27am
common1 replied on Thu, 2009/06/18 - 1:05pm
williamwilliam replied on Sun, 2009/06/21 - 2:26pm
merna replied on Tue, 2009/06/23 - 1:00am
in response to: Gramesmith1
jakiemos replied on Fri, 2009/06/26 - 4:06pm
jiji530 replied on Fri, 2009/06/26 - 8:18pm
KrisBin replied on Sat, 2009/06/27 - 10:46am
seocorporation replied on Fri, 2009/07/03 - 6:25am
Learn how search engine marketing,http://www.ftsilk.com/buy.html PPC management, conversion enhancement and web analytics tracking can boost your online profitability. Visit our website and harness the web with Alkemi. SEOLearn how search engine marketing, PPC management, conversion enhancement and web analytics tracking can boost your online profitability. Visit Alkemi's website for more details about Internet Marketing Services. Seo
honeys replied on Fri, 2009/07/03 - 6:54am
Web Design Finchley Web Design Edgware, Finchley (London): For Web Development Finchley, Web Design/Development Edgware, Website Design/Development in Edgware, Finchley (London), Web Development London visit Indigoideas.co.uk