X

An Oracle blog about NetBeans for PHP

PHP templates improved

Guest Author

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


Join the discussion

Comments ( 15 )
  • Pet Friday, October 16, 2009

    NB keeps surprising us with amazing features! Keep on!


  • Yoosuf Friday, October 16, 2009

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

    http://blog.eyoosuf.com/resources/best-php-ide-and-editors-to-boost-up-your-day-to-day-coding/

    Keep rocking...

    Open source matters..........


  • porcelanosa Friday, October 16, 2009

    Hello!

    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)

    Thanx!


  • Carlos Romel Friday, October 16, 2009

    Hi.

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


  • &#1046;&#1105;&#1087;&#1082;&#1072; Saturday, October 17, 2009

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


  • radek Saturday, October 17, 2009

    To Carlos Romel:

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


  • radek Saturday, October 17, 2009

    To porcelanosa:

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


  • Tomas Mysik Saturday, October 17, 2009

    To porcelanosa:

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


  • Tomas Mysik Saturday, October 17, 2009

    To Carlos Romel:

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


  • e.s.t Saturday, October 17, 2009

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


  • Tomas Mysik Saturday, October 17, 2009

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


  • raymond Sunday, October 18, 2009

    This looks great!

    Are there any improvements on the HTML Template side?


  • Yudi Setiawan Monday, October 19, 2009

    It rocks!

    Thanks for the great work.


  • osman Thursday, October 29, 2009

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


  • Andreas Friday, November 13, 2009

    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! :)


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.