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.
Note the following screenshot, I have highlighted two variables, and my mouse pointer is located on one of the the selected variable. Then I pressed ALT+Insert.
View Screen Shot 1
In that screenshot, only “connect to database” and “database table” menus are available. But the expected menu Generate “Getter and Setter” and etc are not available.
But In the following screenshot you can see, my mouse pointer is located in the class, But not on the variables.
View Screen Shot 2
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.
View Screen Shot 3
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
View Screen Shot 4
The generate functionality is designed that you can work just with the keyboard and you don’t have to use mouse.