PHP templates improved

Today, I would like to show you the latest improvements in PHP templates area.

The first improvement is that one can easily surround his/her code with these PHP statements:

  • while
  • do
  • switch
  • if / elseif
  • try & catch
  • foreach
  • for
  • ob_start & ob_end_clean

How to do that? Very easily, just select the code you want to surround and click a yellow bulb in the left side of the editor (or use ALT + ENTER).

PHP Templates: surround with

Another improvement is that NetBeans tries to find a suitable variable during template generating - on the next image, where we just surrounded our code from the previous example with if (true) PHP template, one can see that "correct" variable has been used as a condition (variable $a in our case because it is a boolean). Also, please notice that the condition is preselected so it can be easily changed if needed (after you are done, just press ENTER and the cursor will be placed in the correct location, just after "$b = 10;" in our case).

PHP Templates: surround with IF statement

Another possibility to insert a PHP template is to type its abbreviation (e.g. "if" for if statement) followed by TAB key.

The next example not only shows an improvement in PHP templates but also in PHP editor - first, we invoke PHP template for foreach statement by typing "foreach" and invoking code completion (CTRL + SPACE). You can see that its abbreviation is "fore".

PHP Templates: code completion for FOREACH statement

The template is generated and as an array, proper variable is used ($arr in our case). And because PHP editor is really smart, the correct methods for $value variable can be offered.

PHP Templates: improved code completion

That's all for today, as always, please test it and report all the issues or enhancements you find in NetBeans IssueZilla (component php, subcomponent editor).


NB keeps surprising us with amazing features! Keep on!

Posted by Pet on October 16, 2009 at 01:44 PM CEST #

NetBeens is one of the best IDE i ever seen, specially the improvements are really great mile stones for a Open Source IDE such as this.

Personally i prefer NB for PHP coding...

see my blog post about the best PHP editors, that netbeens the only IDE having a highlight able features and improvements....

Keep rocking...
Open source matters..........

Posted by Yoosuf on October 16, 2009 at 09:34 PM CEST #

Why my list of "Surround with..." content only "try ... with ..." construction ?
Product Version: NetBeans IDE 6.8 M2 (Build 200910071658) and
Product Version: NetBeans IDE 6.7 (Build 200906241340)


Posted by porcelanosa on October 16, 2009 at 11:02 PM CEST #


What about when NB says: Implements all abstract methods and forget to put the type into generated code?

--- 8< ---
abstract class DAO {
abstract static function something(Model $x); // Note object type (Model)

// Generated code
class X implements DAO {
abstract static function something($x); // Voilà! no object type (Model)
--- >8 ---

Posted by Carlos Romel on October 17, 2009 at 01:47 AM CEST #

Wow, this is really a feature that lacks in most of PHP IDE's. NetBeans FTW!

Posted by Жёпка on October 17, 2009 at 03:09 AM CEST #

To Carlos Romel:
the problem you mention is already fixed in current dev builds (not yet in milestone 2)

Posted by radek on October 17, 2009 at 04:23 AM CEST #

To porcelanosa:
this feature was added after 6.8 M2. So, you must take current dev build or wait for beta

Posted by radek on October 17, 2009 at 04:29 AM CEST #

To porcelanosa:
Use the link in the blog post to get the development version of NetBeans (or wait for NB 6.8 Beta)

Posted by Tomas Mysik on October 17, 2009 at 05:09 AM CEST #

To Carlos Romel:
This should already be fixed in the development version of NetBeans (use the link from the blog post to verify that).

Posted by Tomas Mysik on October 17, 2009 at 05:10 AM CEST #

aahh.. I love fresh smell of new Netbeans in the morning..

Posted by e.s.t on October 17, 2009 at 05:11 AM CEST #

I noticed too late that Radek already answered.... :)

Posted by Tomas Mysik on October 17, 2009 at 05:11 AM CEST #

This looks great!

Are there any improvements on the HTML Template side?

Posted by raymond on October 18, 2009 at 09:24 AM CEST #

It rocks!

Thanks for the great work.

Posted by Yudi Setiawan on October 19, 2009 at 10:18 PM CEST #

netbeans php rocks. and it is getting the best php development platform.

Posted by osman on October 29, 2009 at 05:06 AM CET #

Wouldn't it be better to show the return type on the right side of the completion list instead the containing class, like in Java?

Awesome work with the PHP support! :)

Posted by Andreas on November 13, 2009 at 03:04 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

This blogs is written by NetBeans developers who contribute to the PHP support mainly.


« July 2016