Generate Constructor, Getters and Setters in NetBeans PHP IDE

Tags:

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

0
Average: 3.5 (2 votes)

(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

Nice article and great feature in NetBeans. That and Rename are my most heavily used. Keep up the great work.

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

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. Logo Design | Education Logo Design | Communications Logo Design

common1 replied on Thu, 2009/06/18 - 1:05pm

müzik dinle Online müzik dinleme sitesi. radyo Online radyo dinle. otomatik kapı sistemleri Otomatik kapı sistemleri mantajı ve teknik destek. özel ders Özel ders almak isteyenler için. sohbet odaları Sohbet odalarında konuşun... saat Online saat alışverişi. seo Seo danışmanlığı sağlayan firma. ( custom logo design - stationery logo design - Website Design - Web Marketing )

williamwilliam replied on Sun, 2009/06/21 - 2:26pm

I use setters & getters with magic methods __get __set is very easy to work with this functions... I also normally have variables in the form of myVar, and use getters and setters in the form of getVar and setVar. It works well to me. Business Logo Design

merna replied on Tue, 2009/06/23 - 1:00am in response to: Gramesmith1

Basically there are three types of corporate logo designs - Descriptive, Abstract and Typographic. These options are also to be facilitated to you by the professional web designers, logo design services and business web development companies. The logo design should indicate properly the credibility of your business. Thanks, Life Insurance Quote

jakiemos replied on Fri, 2009/06/26 - 4:06pm

Perhaps you should've made the title of this article "Why getter and setter methods are evil if used inappropriately".Overall, Do you suggest that getters and setters are just bad? in general, any design is never perfect. There's always room for improvement. Tv Guide

jiji530 replied on Fri, 2009/06/26 - 8:18pm

thanks for your post.perhaps you will like abercrombie,ed hardy,mortgage rates,tiffanysanded hardyIs not it?

KrisBin replied on Sat, 2009/06/27 - 10:46am

I emo use setters & getters with magic methods __get __set is very easy to work with this functions. I also normally have variables in the form of myVar, and use getters and setters in the form of getVar and setVar. It works well to me. emo icons

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. SEO

Learn 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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.