The NetBeans IDE for PHP Development
For millions of developers around the globe, the NetBeans IDE is their code editor of choice. An open source project fostered by Sun Microsystems (now Oracle) for more than a decade, NetBeans has grown from a Java-specific solution to a powerful development ecosystem supporting multiple languages and hundreds of extensions (known as plugins to the NetBeans community). Although support for PHP didn't come until the 6.5 release (November 2008), it's already fast becoming one of the PHP community's most popular IDE choices.
In this article I'll introduce the NetBeans IDE from a PHP developer's perspective, highlighting the key features that can make you a more productive PHP developer.
Installing the NetBeans IDE
You can easily install the NetBeans IDE using a platform-specific installer found at NetBeans.org, so point your browser there and click the Download button on the home page. Next, you'll be prompted to choose from several available downloads, as NetBeans supports multiple languages, including C, C++, Java (FX, ME, and others), PHP and Ruby. You can choose the PHP-specific bundle, or select the All option to download the version that bundles universal support for all languages.
Incidentally, for you Ubuntu users like me, as of this article's publication date version 6.8 is not available via Ubuntu's repositories. Instead, you'll also need to download the Linux installer from the NetBeans Website. All you need to do is set execute permissions on the downloaded file, and run it from the command line to begin the installation process.
When complete, fire up the newly installed IDE to begin exploring its PHP capabilities!
Creating a PHP Project
To create a new PHP project, navigate to File -> New Project and choose PHP Application from the list of options. If you're already working on a PHP project and would like to continue doing so in NetBeans, choose the PHP Application with Existing Sources button. In either case, click Next to proceed.
Presuming you're creating a new PHP project, next you'll be prompted to name your project (see Figure 1 below), select a storage location (which presumably will reside within your Web server's document path), and identify the PHP version you'll be using in conjunction with this project (this decision affects only adjustments made by the NetBeans IDE to account for version-specific syntax changes).
Figure 1. Configuring a PHP Project in NetBeans: When creating a new PHP project, you'll be prompted for the necessary information.
Finally, if you require an encoding format other than UTF-8, you can change the default here. When you have made the choices, click the Next button to continue configuring your project.
Next, you'll be prompted to specify whether this project will run locally or remotely. Although I'll presume you're going to run the project on a local Web server, note that you also can configure the NetBeans IDE to upload files to a remote server using FTP or SFTP by setting the project to run remotely. On this screen you'll also define the project URL, which if you're running locally will depend upon how you have configured Apache to access the project's home directory. When the choices have been made, click the Next button to continue configuring your project.
On the final screen you'll be prompted to confirm whether your project will use a PHP framework. Currently only the Symfony framework is listed, but I imagine we'll soon see other frameworks supported here. Keep in mind that even if your favorite framework does not appear here you still can use NetBeans in conjunction with other framework solutions! The upcoming section "Integrating NetBeans and Your Favorite PHP Framework" provides more information about this matter. In the meantime, click the Finish button to create your new project.
PHP offers thousands of native functions, so remembering the spelling and input parameters of even the ones you commonly use can be a real chore. Therefore, perhaps the nicest fundamental PHP feature is the code completion (see Figure 4 for an example), which uses autosense to produce a list of available function candidates based on the function name you've started to type. You can scroll through this list, reviewing the required parameters and definition of each. A link to the manual page is also provided, although later in this article I'll show you a much more convenient way to retrieve a PHP function's manual page.
As your projects grow in size, you can easily lose track of the location of a particular method. Using NetBeans' class browser, you can navigate to the specific location of a class or method definition simply by clicking on its name, as depictured in Figure 2.
Figure 2. Browsing a PHP Class: You can navigate to the specific location of a class or method definition.
Using filters located at the bottom of the class browser, you can filter this listing to show only class fields, class methods, or non-public methods.