PHP Scripting News

Last week, when I was at the IPC 2009 conference, a some user ask me whether NetBeans removes trailing spaces. It was one question from many and I would like to clarify how it works in NetBeans 6.0 - NetBeans 6.8.

Basically it works automatically on save. So when you invoke Save action then the trailing spaces should be removed from the file. There are two exceptions, when the spaces are not removed from a line:

  • The line wasn't changed. The main reason for such behavior is that usually you don't want to have unnecessary changes in the diff, if the files comes from a VCS. So unchanged lines are not touched and if there is a space at the end of such line, then is not removed. When you edit the line then the spaces are removed on save as well.
  • The line where the caret is located. When you invoke Save action, then the position of the caret is not changed. But all trailing spaces after caret are removed.

If you want remove all trailing spaces in the file, you have to invoke action Remove Trailing Spaces from Source menu by hand.

It was one year ago, when I attended IPC conference for the first time in my life (it was my first PHP conference at all). At the time we released NetBeans 6.5 that was the first version of NetBeans with PHP support and only few people knew about NetBeans. The goal was to introduce NetBeans to the PHP developers.

This year I'm going to attend the conference as well. The Internation PHP Conference starts this Sunday. There will be one session about NetBeans on Monday and I will talk mainly about new features in NetBeans 6.8. There will be also a small NetBeans booth where we can meet during the conference. I should be there from Monday to Wednesday. We are looking forward to talking with you. 


We've created a screencast that demonstrates the built-in support for the Symfony framework in NetBeans IDE for PHP 6.8. It shows how to set up the IDE to use Symfony, how to create a PHP project that uses the Symfony framework, and a number of tips, such as handy keymapping to set up in NetBeans IDE.


Today, I would like to show you some improvements done in SQL code completion area (thanks to our colleagues from database team!).

As you probably know, there is already SQL code completion in PHP editor available - but only for SELECT statement. But this has changed recently, now you can enjoy this great feature for INSERT, UPDATE and DELETE statements as well (please note that code completion works for other SQL keywords as well, but not for the first statement in the string - you have to type INSERT/UPDATE/DELETE yourself).

Let's have a look at some screenshots, first for INSERT statement:

SQL code completion for INSERT

SQL code completion for INSERT

SQL code completion for INSERT

Code completion for UPDATE statement works very similarly:

SQL code completion for UPDATE

SQL code completion for UPDATE

SQL code completion for UPDATE

Last, but not leaset, the DELETE statement:

SQL code completion for DELETE

SQL code completion for DELETE

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

We've now finished a screencast demonstrating PHP 5.3 namespace support in NetBeans IDE 6.8. (See Code Completion for Namespaces part I). The screencast also shows code hints for assigning variables, namespace naming hints, and how to set the options for PHP code completion.


I attended this weekend WebExpo 2009 in Prague. I had one session there about developing web applications in NetBeans. Originally I though that the presentation should be divided into two main parts. One part about PHP and second part about Java Web. Because the bulk of the audience were PHP developers, I spent  talking about PHP development in NetBeans almost whole session. After the session there was a long discussion (more than 1 hour) and some people complained about formatting.

As a result I have decided to look at this and to try to fix as many bugs as possible. Because there is not much time for NetBeans 6.8, I would like to ask you for help. I have created task in our Issuezilla, where you can put the cases, when formatting or indentation doesn't work correctly. If you don't have Issuezilla account and you don't want to create it, you can paste the cases here as a comment. A case should contain an example of the code before formatting / indentation and also the same code, but in the right form.

I can not promise that we can fix all these cases, but we will try as many as possible.

Thanks for your help.

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


The NetBeans team is pleased to announce the availability of NetBeans IDE 6.8 Milestone 2.

PHP support focuses on:

Please test it and report all the issues or enhancements in NetBeans IssueZilla.  Share your thoughts on NetBeans' mailing lists and forums.

Hi all, today I would like to announce that the support for Symfony PHP Framework (as we planned it for NetBeans 6.8) is finished. So, what's new?

(If you missed our previous blog post about Symfony support in NetBeans, please, read it here.) 

Now, code completion offers proper Symfony variables in Symfony views.

Symfony variables are present in code completion (I)

Symfony variables are present in code completion (II)

Also, one can very easily navigate between Symfony views and actions. Of course, these actions are not present in other PHP files.

So, if you navigate from view to action... 

Go to Action

... you will end there :)

Navigated to Action

You can navigate vice versa as well (please notice that you must invoke the action from the body of a method).

Go to View

One can assign shortcut for this action.

Symfony Shortcuts

Please notice that these improvements will be available in NetBeans 6.8 Beta (will be released soon) .

Now, it's time to use NetBeans for your own Symfony projects or to follow Symfony tutorial to see whether Symfony support is good enough or should be improved. So, please test it and report all the issues or enhancements you find in NetBeans IssueZilla (component php, subcomponent symfony).

Justin Bolter shows you how to build a PHP Flickr slideshow using NetBeans IDE 6.5. 

From the last week there is recognized PHP language in YAML files. It is only on the lexical level, but it's helpful.  This feature is mainly required by Symfony framework that uses PHP in YAML files.


We are searching for all PHP NetBeans users who would like to help us with testing our new experimental build. Everyone is welcome but we would need a feedback especially from users who often have to switch from NetBeans to command line or any other external application (usually because of running some external tool for versioning, PHP framework etc.). All these external changes should be correctly propagated to NetBeans.
On the other hands, performance, especially on non-local disks, could be slightly worse, so if you have any PHP project with such sources, please, give it a try as well because we are really interested in your results.

So, if you would like to participate on this testing, download the build, start it with -J-Dorg.netbeans.modules.masterfs.REFRESH.level=0 so the useful information can be logged. By the end of August 2009 (the sooner the better), please send us your feedback together with the IDE log (send it directly to tomas (dot) mysik (at) sun (dot) com).

Detailed information can be found on a special wiki page dedicated to this experimental build.

Thanks a lot for your help and for your feedback!


Keyboard shortcuts make your every day life easier, so it make sense to improve your key learnings.

PHP Magazine collected list of Netbeans keyboard shortcuts that could save you a lot of time.

Shortcuts for Mac OS X users.

The ultimate way how to learn keyboard shortcuts for your version of NetBeans is to check out the available shortcuts in Tools->Options->Keymap.

I've just finished making a screencast demonstrating the following features first presented on this blog:


This is brief overview how to use code completion for namespaced elements in NetBeans 6.8.
Namespaced elements are resolved according  name resolution rules.

See examples for namespace name definitions that are important for resolution rules:

// Fully qualified name
$c = new \my\name\ExampleClass();

// Qualified name
$c = new name\ExampleClass();

// Unqualified name
$c = new ExampleClass();

Now we have 3 ways how to create new instance of class ExampleClass. Let's look how to harness code completion to generate all of them.

Fully qualified name

Simply begin with a namespace separator after new keyword (e.g. new \Exam), choose from the list of proposals and press enter. 

fully qualified name proposals

As a result:

fully qualified name result

Unqualified name

 The same as for fully qualified name - just omit namespace separator at the beginning (e.g. new Exam).

qualified name proposal

As a result:

qulified name result

Qualified name

Begin with a sub-namespace name (whereas code completion can be used here also ) followed with namespace separator after new keyword (e.g. new name\Exam), choose from the list of proposals and press enter. 

qualified name proposal

As a result:

qualified name result

As mentioned above, for sub-namespace name can be used code completion too.

namespace name proposal

For e.g. new name\test\Exam can be used code completion 3 times: name, test, Exam.

At CommunityOne, the Sun GlassFish Web Stack team gave a "Deep Dive" series of presentations on the web stack. Sun GlassFish Web Stack includes a fully integrated Apache, PHP, and MySQL package, as well as the GlassFish and Tomcat servers and Python and Ruby support (and lots of other stuff, too). It's currently available for OpenSolaris and Linux RedHat. (Note that if you don't want OpenSolaris as an OS on your machine, the stack works very nicely on OpenSolaris in a Sun Virtual Box VM.)

The team's presentations are available as videos from Sun Learning Services. If you don't mind getting a My Sun Online account (or you already have one), you may find these presentations interesting.

Probably the two most broadly relevant presentations are:

  • https://slx.sun.com/1179274784 - Introduction to Sun GlassFish Web Stack Deep Dive. This describes the web stack and all the technologies it incorporates, as well as the differences between the OpenSolaris and RedHat versions.
  • https://slx.sun.com/1179274787  - NetBeans and DTrace. This presentation first shows how the PHP web stack is integrated with the OpenSolaris desktop. Features include setting the PHP web stack options without manually editing configuration files, including how to enable debugging with NetBeans. The presentation also demonstrates the NetBeans features for developing PHP applications and the DTrace plugin for NetBeans.

Other interesting presentations are:

Lastly, for Ruby developers, there is https://slx.sun.com/1179274794 - Ruby in Sun Webstack.

We are pleased to announce that NetBeans IDE 6.8 M1 Download is now available. Visit the NetBeans 6.8 New and Noteworthy page to learn more about all the new features and enhancements available in this milestone release. The final release of NetBeans IDE 6.8 is planned for Fall 2009.

Highlights of this stabilized development build include the initial support for the  6.8 key PHP features:

Support for PHP 5.3 language features in NetBeans IDE 6.8

One of the goals for NetBeans IDE 6.8 is to bring support for the new language features in PHP 5.3, such as new keywords, namespaces and closures. Now I would like to share information about status of PHP editor features for Milestone 1.

Milestone 1 Features

Syntax Highlighting for new keywords, closures

syntax coloring 2

Code Folding for namespaces

syntax coloring

Navigator shows namespace declarations

navigator 5.3

aliases/imports, constants declared outside a class using the const keyword planned for milestone 2

Code Completion after use, namespace keywords, identifiers with qualified names

cc in namespace segments

cc53newinstance

Please test it and report all the issues or enhancements you find in NetBeans IssueZilla (component php, subcomponent editor).

We have a program for NetBeans users to submit their own tutorials, tips and tricks, and how-to docs. It's called Community Docs, and the portal is at http://wiki.netbeans.org/CommunityDocs. It's very popular. However, there have been no submissions from PHP developers! So, I was thinking, perhaps none of you know about it? If any of you have any cool examples of apps that would be the basis of a nice tutorial, or have tips for other users, please consider posting a full description over there. It's a big help to everyone.

Recent improvements in PHPUnit-support

This blog post has been contributed by Thomas Meyer who has helped a lot with these improvements. Thanks a lot, Thomas!

Today I want to introduce some new features and fixes, that will greatly improve the support for - and usability of - PHPUnit in NetBeans.

Enabling PHPUnit

First allow me to explain, how to enable PHPUnit in NetBeans. Click the menu "Tools" > "Options" and select the "PHP" tab. The screen below shows the two options that you need to change.

PHPUnit Properties

First: Enter the path to the command line script you wish to run in NetBeans. This requires that you have a local copy of PEAR and PHPUnit 3.3 already installed on your system.

Second: To enable code-completion for your test cases and test suites, please specify the path to PHPUnit's class-files.

New options in project-properties

You will now find options to configure PHPUnit for you project within the project properties menu. Just right-click on your test-folder and choose "properties" to bring up the dialog.

PHPUnit Project Properties

You may choose a custom configuration XML-file, bootstrap-file and a custom test suite. If you are not familiar with the structure of these files, you may let NetBeans generate a skeleton for you.

The bootstrap option is required for projects that use a custom class loader, for example by implementing the __autoload() magic function. You also use the bootstrap option if you need to include a file in advance, such as a file that defines global constants used by several classes of your project.

The XML configuration file allows you to define any of the options you could use in a command line call and more. You will find a complete introduction in the PHPUnit manual. You may find the ability to define php.ini settings and global vars for your test cases quite useful. Note that you may alternatively set the bootstrap option in the XML configuration file too.

Last but not least you may choose a custom test suite that will be run whenever you select "run" > "test project" in NetBeans. This is particularly useful when you wish to run just a subset of your tests, or if you want to use some recently added features of PHPUnit like Data Providers. Data Providers are reported to require that you manually add them using PHPUnit_Framework_TestSuite::createTest() and thus are one example for when you will definitely need a custom test suite.

Note that you may of course define as many test suites as you want and run them separately by right-clicking the file in your project explorer and choosing "run".

To prevent confusion, NetBeans notifies you if you use your own Test Suite. The notification can be found in the Test Results,

Custom Test Suite in Test Results

as well as in the Output window.

Custom Test Suite in Output

Of course, if any of these files is missing, a warning is displayed so you can quickly fix the problem.

Missing Files Warning

Improved code coverage report

You may already know how to test your project - but how do you test your tests? The solution is to generate a code coverage report. It will not only tell you how many percent of your project is already covered by unit tests, it will also tell which lines in your code are executed during testing and (more importantly) which are not.

Note that you may need to raise PHP's memory limit in php.ini before you are able to create your first report. I suggest setting it to at least 500MB. I have seen a PHP process using a peak of 300MB on my machine while generating the report for a small project with only 30 test cases.

If you are already used to code coverage in NetBeans 6.7, you may have noticed that the presented statistics were based on lines of code. It was counting empty lines and comments alike as tested code. We decided to change that behavior, as it showed a tendency to report far too high coverage percentages.

Improved Code Coverage

The improved code coverage report in NetBeans now is based on the real number of statements which are actually executed, giving you much more precise results, as the screen above shows.

You will also witness these changes when you display the coverage of a single file. It now corresponds with the results you get by creating a PHPUnit coverage report via it's command line interface.

Displaying Coverage of Source File

The screen shows that only executable statements are colored. White-space and comments are ignored. Covered statements are marked green, while statements that haven't been executed during the test are marked red.

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

NetBeans IDE 6.7.1, which supports the latest JavaFX SDK, is now available for download. The release is an update to NetBeans IDE 6.7 and includes the following changes:
  • Support for JavaFX 1.2
  • Upgrade of GlassFish v3 Prelude to include fixes from build #28f
  • Integration of important bug fixes based on user feedback, especially in the Java Editor and project scanning areas
Learn more about NetBeans IDE 6.7.1 and download the release today! (See the original announcement.)

Today, I would like to introduce you a very nice feature that many (really many) of you wanted to see and use. In the development version of NetBeans, one can ignore project's folders - what does it mean? It means that one can specify folders that are not visible in the UI but mainly, they are not scanned and indexed (example of such folder could be a directory with generated documentation etc.). Have a look at Project Properties dialog:

Ignored Folders

Please notice that due to bug 168460, IDE must be restarted.

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


Today, I'm going to write a very short blog post about 2 minor improvements in FTP/SFTP support in NetBeans.

The first improvement is providing detailed information about the file transfer progress (uploading as well as downloading) and we hope that many our users will find it useful. The information is based on file size so it should be quite accurate.

File Transfer Progress

The other improvement is more UI enhancement but again, we hope that it will be useful as well.

Transfer Summary in Colors

As I promised, this blog post was very short but please, do not forget to test it and report all the issues or enhancements you find in NetBeans IssueZilla (component php, subcomponent ftp support).

Today, I would like to inform you that we have added initial support for the popular PHP framework - Symfony (the most voted issue in NetBeans IssueZilla).

Please notice that the support is still quite minimal and we would like to improve it a lot, there are still many things to do. So, let's have a look what's available right now.

Existing Symfony projects should be recognized automatically but of course, one can create a new PHP project with Symfony framework:

New PHP projectwith Symfony framework

The main support now is the possibility to run Symfony commands:

Run Symfony Command

The UI for the commands allows to:

  • filter the Symfony commands (1),
  • specify command parameters (2),
  • select a command (3),
  • see help of a command (4) and
  • preview the whole command that will be run (5).

UI for Symfony Commands

Please notice that the list of commands is project specific, it means that if one uses e.g. Doctrine instead of Propel, no Propel commands are listed, just the Doctrine ones. Also, all the commands from project's Symfony plugins should be available.

Of course, the output of the currently running command is displayed in the Output window, directly in the IDE.

Output of Symfony Command

UPDATE:

It could be useful that one can specify shortcuts for Symfony actions.

NetBeans Keymap

The Symfony script should be detected automatically but it can happen that it's not found so one can specify it in the IDE Options.

Symfony Options

That's all for today, now it's your turn so please, test it and report all the issues or enhancements you find in NetBeans IssueZilla (component php, subcomponent symfony).

Thanks a lot and happy Symfony coding!


First let me announce the availability of NetBeans IDE 6.7!

I would like to thank everyone who helped us to make the IDE better. Thanks for every reported issue, comment or contributed fix. To learn more about NetBeans IDE 6.7 please use the following resources:

Second announcement is that long awaited PHP 5.3.0 is released!

PHP 5.3.0 brings new feautures and bug fixes. See announcement for more details. NetBeans IDE 6.8 will bring support for PHP 5.3.0.  For everyone who is eager to play with new features I can recommend to download one of latest PHP daily builds and try our current support. You may be pleasantly surprised and we are curious about your feedback. Definitely you can expect more blog entries announcing individual features in the couple of next weeks.

When you work on a project, you need to navigate around the source code frequently.  NetBeans  IDE provides many navigation features that are highly useful since 6.5 but there were additional improvements and fixes in 6.7 that are worth of mentioning.

Go to File (Alt+Shift-O)

Much faster now, type file name and you will be pleasantly surprised how fast it is, its the difference especially on huge projects.   

Go to Type (Ctrl-O)

Camel cases can be used now. You can try any of following patterns :

  • MyDatabaseResult
  • MDR

if you wish to find MyDatabaseResult class/interface.

Quick Search (Ctrl-I)

Quickly search for action or type is now easy.

Go to Symbol (Ctrl+Alt+Shift-O)

Powerful - finds  functions, methods, fields, constants, types. Just type its  plane name or camel case patterns.

Go to Test (Ctrl+Shift-T)

PHPUnit support was added to NetBeans. Use Go to Test action it if you need to switch between test and tested source file.

Go to Declaration (Ctrl-B)

Radically improved, fixed many problems, more reliable. One of its improvements described here Go to Declaration for class members

The paragraphs above highlits code navigation improvements in 6.7 that should be released very soon. Release Candidate 3 is now available for download.

NetBeans 6.7 is nearly out so it's time to start developing new features for the next release...

Today, I would like to inform you that we have just added one thing that could help people who would like to develop their PHP applications that are on a remote server. For such users, we have added a new PHP project wizard that takes care about correct project setup. Now, let's try to create such project:

First, invoke new project wizard, select PHP and then PHP Application from Remote Server.

New PHP Application from Remote Server wizard

The next step, Name and Location, is already well-known so let's skip it here and continue with the last step.

Remote Settings

As you can see, NetBeans asks you only for minimum information - project URL (to be able to run the project) and a remote server together with a remote directory (to be able to download/upload the project).

If we click Finish, remote files are downloaded to the newly created project.

Download Progress

Of course, everything is logged so one can see the progress as well as investigate if any error occurs.

Remote Log

The newly created project is properly configured so every single change to your source files should be immediately propagated to your remote server so you can easily run the project or a file.

Remote Project Properties

That's all for today, we hope that you will welcome this feature, especially users who don't have their own server/PHP/database installed locally. And as always, please give it a try and report all the issues you find, thanks a lot.


How to include file in PHP NB IDE? Two ways:

  1. file system code completion for include/require
  2. Fast Import Alt+Shift-I

The first one is probably no surprise because is included in NB since 6.5

Include, Require CC

The second one was added into 6.7

Fast Import

Fast Import, looks at the identifier under the editor caret, then tries to locate the file and if successful we get the dialog like in the screenshot above. The choice is obvious and after pressing "Enter" we are done and include or require statement is generated.  By pressing "ALt+Enter" the statement will be generated just before the current line.


Last week I've got a question: "I need to explain when the Introduce Variable hint is invoked?" and I've realized that I could mention it briefly in this weblog because I'm not sure how many of you have already noticed it. I like this feature because I have a feeling that it boost my productivity. As an example imagine following common OOP piece of code:

<?php
$simpleClass = new SimpleClass();
?>

To create an instance of a class, a new object must be created and assigned to a variable. An object will always be assigned. This hint appeares just in the moment when assignment is ommited:

Introduce Variable Hint Annotation

Then Alt+Enter is enough to fix it and assign it to a variable.

The other typical use cases when this hint appears: function, method invocations. So, on every line in the following piece of code this hint should appear:

<?php
new SimpleClass();
$simpleClass->getSimpleValue();
SimpleClass::getSimpleKind();
calculate();
?>

The implementation doesn't try to find out whether the function or method really returns a value, it's left just up to the user's decision whether to use or not use this hint.  

The last note I would like to mention is that the name of generated variable on left side is taken just from the right hand side and is preselected to be able to modify it instantly. See the screenshot:

Introduce Variable Hint

Please comment or report bugs, I will wait for your feedback.

Many of you would like to have remote synchronization for your PHP projects - well, let's have a look what we have done.

First, you have to define a Remote Web Site configuration for your project; I'm pretty sure most of you already know how to do that but let's repeat it once more: right click your project in Projects view and select Properties. In the Project Properties dialog, choose Run Configuration and as a type select Remote Web Site (or, if you are currently editing a PHP file of your project, just choose Customize... from the combo box in the main toolbar). You will notice that now one can select On Save for Upload Files (the first highlighted area on the image). Please note that now it's also possible to speed up an upload a bit but as the label says, use this with caution (the second highlighted area on the image).

Remote Web Site configuration

You are done! Seriously, from now, every change (create, edit, rename, delete) should be immediately propagated to your remote server. One more note - if the operation takes more than 1 second, progress bar is shown:

Remote Synchronization

The same applies if one uses local copying under a document root of a web server (it can be found in Sources category of Project Properties dialog):

Local Synchronization

That's all for today, and as always, please use our development version of NetBeans to try it and let us know if you find any problem.

Thanks a lot, we hope that you will like this feature!


NetBeans IDE 6.7 Milestone 3 (M3) was announced. Read the complete list of NetBeans IDE 6.7 Milestone 3 features and enhancements.