PHP Support in NetBeans 6.5

Share this article

Long dismissed as a “toy Java IDE”, NetBeans—Sun’s open source Integrated Development Evironment (IDE)—has really grown up in recent years. No longer is it just for Java, either: for web developers, NetBeans 6.5 now supports Ruby and PHP out of the box. Surprisingly, that support is so good that it now compares favourably to more established competitors like Eclipse, Komodo IDE, and Zend Studio.

I had become used to writing my PHP code in a simple text editor (jEdit, if you’re wondering), so it had been awhile since I’d enjoyed the luxuries of project-wide code completion, code refactoring, and a full debugger. All of these and more are available in NetBeans 6.5.

NetBeans includes autocomplete not just for built-in functions…

Screenshot showing the NetBeans code editor recognizing and autocompleting the str_repeat function built into PHP, along with pop-up documentation

but also for functions defined elsewhere in your project and included libraries:

Screenshot showing the NetBeans code editor recognizing and autocompleting the registerObserver method on a custom PHP class, along with pop-up documentation

In both cases, NetBeans picks up on phpdoc comments in your code and uses them to display pop-up documentation along with its autocomplete suggestions.

Once you select a code completion for a function or method, NetBeans assists you in filling in each parameter. When you’re done filling in one parameter, hit Enter to automatically move to the next parameter.

Screenshot showing the NetBeans code editor with a box around the first parameter of a str_replace function call, to indicate it is selected for editing

NetBeans also comes with PHP code templates for developers who like to set coding speed records. For example, type fnc and then hit the Tab key. NetBeans will expand it into a full function declaration, and prompt you to fill in a function name, before placing your cursor in the function body:

Screenshot showing the NetBeans code editor with a box around the function_name portion of a PHP function delcaration

Because having complete phpdoc documentation for your code makes coding in NetBeans so much easier, NetBeans will even assist you with writing your documentation! Place your cursor immediately above a function declaration, type /** and hit Enter. NetBeans will automatically generate a phpdoc comment with placeholders for each of the function’s parameters and its return value:

Screenshot showing the NetBeans code editor having just auto-generated a phpdoc template based on a function declaration

NetBeans’s editor has plenty of other nice features, like variable name refactoring. When your text cursor is on a variable name, all other occurrences of that variable are highlighted in yellow. Type Ctrl+R and you can edit every occurrence of that variable name at once, to instantly rename it throughout the file:

Screenshot showing the NetBeans code editor with boxes around all three occurrences of the $testvalue variable, with the cursor positioned to indicate the second of these occurrences is currently being edited

And of course you can ⌘-click (Ctrl-click on Windows) on any variable, function, or class name to jump immediately to the place where it was declared—even if it’s in another file of your project.

NetBeans 6.5 combines all this PHP editing power with full support for server-side debugging with the XDebug PHP extension. You can set breakpoints in your scripts and step through your code line-by-line, inspecting the values of variables as you go.

Of course, writing PHP applications is more than just PHP code. You have to write HTML, CSS, and JavaScript code as well. When you do, you’ll be pleasantly surprised to find the same level of support for these languages built into NetBeans too! And when a single file mixes these languages together, NetBeans handles it all seamlessly.

If all those code editing features weren’t enough, NetBeans 6.5’s other core features combine to complete the experience. Built-in support for version control systems including CVS, Subversion, and Mercurial (with others, like Git, available as free plug-ins) is especially welcome, with colored bars along the sides of your code to indicate lines that you have changed since your last commit.

NetBeans isn’t a toy for learning Java anymore. These days, it’s a powerful, multi-language development environment that’s free for the taking. If you work on sizable PHP projects and you’re not using an IDE like NetBeans, you might be surprised at how much time a tool like this can save you!

You can learn about NetBeans’s PHP support and download the IDE from the NetBeans PHP Development page. And if you’re interested in following the new PHP-related features that are being worked on for the next version of NetBeans, be sure to follow the NetBeans PHP Blog.

Kevin YankKevin Yank
View Author

Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week