Petr has posted 6 posts at DZone. View Full User Profile

Generate Constructor, Getters and Setters in NetBeans PHP IDE

07.30.2008
| 80538 views |
  • submit to reddit

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

Published at DZone with permission of its author, Petr Pisl.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

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

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

When I heard of the generate getter/setter functionality I thought everything was already working for php, but I could not put this work either. ...

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

i gotta say this is a good program amish rifle t-shirts

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

The HTML5 Microzone is a very cool addition because it is the hottest development area, and it is receiving a lot of coverage. The problem with HTML5 is that it does not fit cleanly with typical delineations of content. -  -Paul Perito

Steve Sdas replied on Tue, 2012/09/25 - 8:05am

After choosing Getter and Setter... item in Generate menu, the dialog offers only $age property, because only this property has neither getter nor setter. Las Vegas

Steve Sdas replied on Tue, 2012/10/30 - 7:03am

I absolutely liked the way you have designed your blog, it's simple, neat, simple to navigate and incredibly easy on the eyes.get your 3 bureau credit reports

Steve Sdas replied on Wed, 2012/10/31 - 5:12am

I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers.equipo para gimnasio

Steve Sdas replied on Sat, 2012/11/10 - 6:48am

This looks amazing. I would love to be in a place like this relaxing reading a book. Well hopefully some time soon.get instagram followers

Steve Sdas replied on Mon, 2012/11/12 - 12:40pm

Recent times when internet has so much gossiping and stuff, your content really refreshes me. punggol ec

Steve Sdas replied on Thu, 2012/11/15 - 6:01am

I stumbled upon my answer for exactly what i was looking for. Thanks to suit the amazing post looking to find more quality post.tapetes para entrada

Steve Sdas replied on Thu, 2012/11/15 - 3:01pm

I found your website perfect for my needs. It contains wonderful and helpful posts..alfombras para trafico pesado

Steve Sdas replied on Sat, 2012/11/17 - 1:25pm

I would love to be in a place like this relaxing reading a book. Well hopefully some time soon.tumblr

Steve Sdas replied on Sat, 2012/11/17 - 3:59pm

One reason may be that it’s intimidating, and like going in the water at the beginning of the season, getting your feet wet is the hard partSAMSUNG GALAXY S3

Steve Sdas replied on Sun, 2012/11/18 - 3:39am

Thank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideasTapetes plasticos

Steve Sdas replied on Tue, 2012/11/20 - 12:41pm

I’m inspired with the surpassing and preachy listing that you furnish in such little timing. tile denver

Steve Sdas replied on Tue, 2012/11/20 - 2:39pm

I hope that such workout will be of great help in maintaining a good health, especially for the working mothers.custom floor mats

Steve Sdas replied on Wed, 2012/11/21 - 10:31am

I would surely give 10 on 10 for such incredible content. chorusdesign

Steve Sdas replied on Mon, 2012/12/03 - 9:55am

I sent your articles links to all my contacts and they all love it including me.Brander Accounting

Uilly Tocky replied on Tue, 2012/12/04 - 12:45pm

I’m inspired with the surpassing and preachy listing that you furnish in such little timing. Bathroom renovating

Uilly Tocky replied on Wed, 2012/12/05 - 5:58am

Fantastic work man, keep your heads high you did it. online casino games

Uilly Tocky replied on Mon, 2012/12/10 - 3:21am

I really enjoyed it...and i really appreciate to you for this....its always pleasure to read so....Thanks for sharing !! annual free credit report gov

Uilly Tocky replied on Fri, 2012/12/14 - 3:48pm

Your contents are wonderful and advisory. rechargeable heated gloves

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

Your place is for sure couturier bookmarking. buy instagram likes

Comment viewing options

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