Skip Headers
NetBeans Developing Applications with NetBeans IDE
Release 7.4

Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Feedback page
Contact Us

Go to previous page
Go to next page
PDF · Mobi · ePub

20 Developing PHP Applications

This chapter describes developing PHP applications for NetBeans IDE, including editing, debugging, and using continuous build servers.

This chapter contains the following sections:

20.1 About Developing PHP Applications

NetBeans IDE (Integrated Developer Environment) for PHP provides tools for PHP programmers. The core of NetBeans PHP support is the PHP Editor, which includes code completion and other programming aids. NetBeans IDE for PHP can also be integrated with the Xdebug debugger, PHPUnit tester, and PHPDocumentor documentation generator.

Please note that the NetBeans IDE is designed to be as lightweight as possible. It does not contain visual design tools or other heavy-duty features.

20.1.1 Databases

The IDE supports working with databases. Open the Services window and register your database by right-clicking the Databases node. You may need to add the path to your database driver as well. NetBeans IDE provides a tree view of database contents and an SQL editor. For more information, see Section 23.3, "Setting up a Database Connection."

20.1.2 Remote Development

The IDE includes support for Subversion, Mercurial, and Git versioning systems. You can also add CVS support as a plugin. For more information, see Section 3.1, "About Versioning Applications with Version Control."

The IDE also provides basic support for FTP/SFTP, sufficient for a lone developer to work on a simple project. If you are working on a complicated project or with multiple developers, you should use a version control system. If you must use FTP/SFTP with a complicated project, consider using the IDE in combination with a full-featured FTP client.

20.1.3 Public Releases and Development Builds

To see the latest features and try them out while they are in progress, install a daily development build of the IDE. For a safer alternative, use the public release. Both public release and development builds can be installed from

20.1.4 Getting Help

In addition to the topics shown here, NetBeans IDE for PHP provides the following sources of information:

  • Context-sensitive help. Click the Help button in a dialog to see a description of the options in that dialog. Context-sensitive help is also available for the Editor, Projects, Services, Files, and other windows. Select any item in a window and press F1 to see the help for that window.

  • Web-based tutorials. See the PHP Learning Trail at

  • NetBeans PHP Users Forum and Mailing List. A forum for PHP users is available at

  • This forum is mirrored as a mailing list. Subscribe to the mailing list or the forum at

  • NetBeans PHP Blog. The NetBeans PHP development team keeps a blog where you can learn about future plans and the latest NetBeans features. Comments welcome! See the NetBeans PHP blog at

For a more detailed description of NetBeans PHP Editor features, please see the NetBeans IDE for PHP Editor, at

20.2 How to Work with PHP Applications

Before you begin to work with PHP applications in the IDE you need to install and configure your PHP environment. The PHP environment includes:

20.2.1 Working with PHP Applications

The following workflow shows how to work with PHP applications.

Create and configure a project

Launch the New Project Wizard (Ctrl+Shift+N). You can create an empty PHP project, a project from existing sources, or a project from remote sources. The New PHP Project wizard helps you create a default run configuration for the project. Later you can change the project's configuration or add additional run configurations by right-clicking the project's node in the Projects window and choosing Properties.

Run project

Right-click the project's node in the Projects window and select Run. If the project's run configuration is set to use a local web server, a browser opens and displays the project's index page.

Note that if the project is configured to run as a command-line script, you have to run it from the command line.

For more information, see Section 20.3, "About PHP Projects in NetBeans IDE."

Test project

You can use PHPUnit and Selenium to test a PHP project.

Debug project

If you configure Xdebug to work in your PHP environment, you can debug a PHP project from inside the IDE. For more information, see Section 20.5, "How to Debug PHP Applications."

20.3 About PHP Projects in NetBeans IDE

A project is a group of source files and the settings with which you run and debug those source files. In the IDE, PHP development takes place within a project, though you can also edit, run and debug a PHP file that is not in a project.

To create a project, click Ctrl+Shift+N, or click the New Project icon. You can create an empty PHP project or you can convert an existing PHP application to a NetBeans project. You can also create a project with sources on a remote server, over FTP or SFTP. However, it is preferable to use version control with remote projects and use the version control system to commit your changes to the remote server.

20.3.1 Source File and Metadata locations

By default the IDE places all project files in your web server's public folder (such as /htdocs). The IDE reads the location of your web server from your PHP environment. However, you have other options for file locations. These options appear in the New Project wizard:

  • Have the NetBeans metadata stored in another folder.

  • Copy the source files to another location. With this option, you could keep the PHP project in one location (such as the same folder as your Java projects) and the IDE could copy it to the public folder of your web server.

20.3.2 Run Configuration

Every NetBeans PHP project has at least one run configuration. You set this default configuration when you create the project. You can add as many additional run configurations as you want. In the Projects window, right-click on the project's node and select Set Configuration to switch between run configurations or add a run configuration. In a run configuration, you set whether the project runs:

  • As a local web site, on your local web server (default)

  • As a remote web site, over FTP/SFTP. You can also set up remote synchronization.

  • As a command-line script

20.3.3 Frameworks

The IDE supports some PHP frameworks. Add a framework to a project when you create the project by selecting the framework in the last page of the New PHP Project wizard. If a project includes framework support, that framework's commands are available in the project's context menu in the Projects window.

20.3.4 Opening and Closing Projects

To open an existing project, click Ctrl+Shift+O or choose File > Open Project to open a dialog box in which you can browse for the project.

To close a project, choose File > Close Project, or right-click the project's node in the Projects Window and choose Close.

20.3.5 Projects Window

Your open PHP projects appear in the Projects Window. To open the projects window, click Ctrl+1 or choose Window > Projects.

If you right-click a project's node or a file's node, a context menu appears. For information about the functionality you can access in the Projects window, select any item in the Projects window and press F1 to view the corresponding help topic.

20.3.6 Adding Files to a Project

To add a file to a project, go to the Projects window and select the project's node or the node for the folder in which you want to place the file. Then open the New File wizard, either by pressing Ctrl+N or the New Files icon, or through the node's context menu.

20.4 How to Edit PHP Files

The IDE contains a number of features that simplify editing PHP files, including syntax highlighting, code completion, using templates, and more. This section describes these features.

20.4.1 How to Highlight Syntax

The editor provides syntax highlighting for PHP, HTML, JavaScript, and CSS code blocks.

The following syntax elements are highlighted in the current version:

  • PHP keywords

  • PHP variables

  • PHP constants

  • HTML tags

  • HTML input form attributes

The current line is displayed with a light-blue background.

By double-clicking a PHP variable, a function, or a class, all the occurrences of the variable are highlighted in olive green.

Lines where errors have been detected are underlined in red.

To change the settings for highlighting, choose Tools > Options and switch to the Fonts&Colors tab. Specify the settings of your choice.

20.4.2 Using Code Completion

Code Completion is a common name for a set of features that facilitate and speed up the process of coding.

The following types of code completion are provided:

  • Snippets

  • Context-sensitive proposals

  • Abbreviations

  • Code Completion in Constructors

  • SQL Code Completion

  • PHP 5.3 Namespaces

  • Overridden and Implemented Methods

  • Annotations

  • PHP 5.4 Traits Snippets

Snippets enable the user to generate code for various elements automatically.

  1. Choose Tools > Palette > HTML/JSP Code Clips. A palette containing various user interface elements appears in the right-hand panel.

  2. Drag the required icon on the palette to the relevant position in the code. A dialog box for specifying the parameters of the corresponding elements appears. Fill in the data.

  3. The code that displays the chosen element is generated and inserted in the chosen location. Context-Sensitive Proposals

The editor provides context-sensitive proposals for completing any number of starting symbols of the following:

  • A PHP keyword (for example, if, else, elseif, while, switch, function, and so on)

  • A PHP built-in function (for example, substr, count, and so on)

  • A pre-defined or user-defined variable

The editor not only suggests expansions but also provides parameter hints.

To apply Code Completion:

  1. Type the starting symbols of the required character string.

  2. Press Ctrl+Space. A drop-down list shows the context-sensitive proposals. Each proposal is supplied with a description and parameter hints. The contents of the list change as you continue typing.

  3. To obtain a list of the PHP key words that are available in the current context, press Ctrl+Space without any previous typing.

  4. To obtain a hint on a variable, type the dollar symbol "$". A list of all the currently available local and global variables appears. Code Templates and Abbreviations

In the current context, the term "abbreviations" refers to a set of predefined character strings that correspond to the key words used in a programming language. Each abbreviation is associated with an expanded text which contains the full key word and a code template for the key word with parameter hints. To apply this functionality, type an abbreviation and press Tab. The abbreviation is replaced with the corresponding key word and the code template for the key word is provided.

To view the list of defined abbreviations with code templates:

  1. Choose Tools > Options > Editor > Code Templates.

  2. From the Language drop down list, select PHP. The list of PHP abbreviations and code template defined for them is displayed.

  3. To add or remove a definition from the list, use the New or Remove buttons respectively.

  4. To edit a definition, select the relevant row and edit the text in the edit field below the list.

For more information, see the following entry on the PHP blog: Code Completion for Constructors

After the new keyword, the code completion window is displayed with constructors and parameters for all available classes in the project. SQL Code Completion

SQL code completion displays when a string begins with the SQL keyword "select." The first step is to select the database connection.

All database connections registered with the IDE are displayed. After you select the connection, SQL code completion offers all tables from that database connection. If the table has columns, those are displayed as well.

SQL code completion also works with table aliases. PHP 5.3+ Namespaces

Code completion supports fully qualified, partially qualified, and unqualified namespace names from PHP 5.3. The IDE also helps you resolve missing namespace use statements. Inside a namespace where you want to fix missing use statements, either right-click and select Fix Uses..., or press Ctrl+Shift+I and go to Source > Fix Uses... A dialog opens offering fully qualified names for each needed use statement. For more information, see the following entry on the PHP blog: Overridden and Implemented Methods

Code completion between class members offers to override or implement methods. Annotations

NetBeans IDE code completion supports the following types of PHP annotations:

  • ApiGen (legacy PHPDoc annotations)

  • PHPUnit

  • Doctrine 2 (ORM and ODM)

  • Symfony 2

Every annotation can be associated with a context. NetBeans IDE recognizes four contexts:

  • function

  • class/interface (type)

  • method

  • field

You can add more annotations to code completion in Tools > Options > PHP > Annotations. PHP 5.4 traits

Traits are a mechanism of code reuse introduced in PHP 5.4.0. The IDE recognizes traits syntax and code completion includes methods, functions, and anything else inherited from or declared in a trait. For more information, see the blog post at

20.4.3 Using Bracket Completion

The editor automatically adds and removes matching brackets and quotes while the user is typing the code.

  • Paired single (' ') and double quotes ("" ""), braces (()) and brackets ([]) are added when the user has typed the first symbol.

  • At the end of a line, a semicolon is added in addition to the closing single or double quote.

  • The closing curly brace is added after the user presses Enter, which also activates the Smart Indent function.

  • Deleting the opening single or double quote, brace, or bracket causes automatic removal of the corresponding closing symbol but does not affect the line end semicolon.

  • When the cursor points at a closing brace, a closing curly brace or a closing bracket, the paired opening symbol is highlighted in yellow.

20.4.4 Using Parameter Hints

The editor prompts the user regarding the formal parameters of a function or a method in the context where the function or method is called.

To use parameter hints:

  1. Type the starting characters of the function you want to call.

  2. Press Ctrl+Space. A dropdown list shows the context-sensitive proposals with the formal parameters for each proposal.

  3. Choose the relevant proposal and press Enter. The name of the chosen function is inserted in the code and a template for entering the parameters is shown in brackets.

20.4.5 Using the Go To Declaration Feature

The Go To Declaration function navigates the user from an occurrence of a variable to the line where the variable is declared or initialized. To use this functionality, position the cursor on the relevant variable occurrence and choose Navigate > Go to Declaration from the context menu, or press Ctrl+B.

20.4.6 Using Rename Refactoring and Instant Rename

Rename Refactoring lets you rename an element such as a class name across all files in a project. The feature forces you to preview your changes before you can make them. The preview window shows you every location of the element and lets you exclude individual occurrences of the element from being renamed.

Instant Rename is a simpler function that only works in "non-public" contexts, such as renaming a variable inside a method, or renaming private variables and fields. Instant Rename lets you only rename an element within a file and does not provide a preview window.

To use Instant Rename, place the cursor on a name you want to change and press Ctrl+R. If Instant Rename applies to that variable, all instances of that variable or function name are highlighted. Change one instance of the name and all other instances in the file are changed simultaneously

To use Rename Refactoring, select the element you want to rename and either press Ctrl+R or right-click and select Refactor > Rename. A dialog opens for you to rename the element. Rename the element and press Preview. The Refactoring window opens. In this window, you can find every instance of the element in your project and decide whether or not to rename it.

20.4.7 Using Code Generators

When you press the combination Alt+Insert (Ctrl+I on Mac), a menu opens with all possible code generators. The list of generators is context sensitive. It depends on the position of the caret in the code when the key combination is pressed. Depending on your position in the code, you can generate a database connection, database tables, lorum ipsum text, and several others. This section describes only the following code generators:

  • Constructors

  • Getters and Setters

  • Overridden and Implemented Methods Constructors

You can generate constructors by pressing Alt+Insert (Ctrl+I on Mac) when the caret is inside a class body, but not inside any functions contained in that body. When you select Generate... Constructor, a dialog opens listing the fields you can initialize by the constructor. The field names are used as parameters of the constructor.

You can decide not to select any fields. In this case, the IDE generates an empty constructor, with no parameters. If the field is a class with properties, you can either select individual properties, or you can select the class, in which case all the class' properties are selected automatically.

For more information, see the following NetBeans PHP blog post: Getters and Setters

You can generate getters and setters by pressing Alt+Insert (Ctrl+I on Mac) when the caret is inside a class body and selecting Getter, Setter, or Getters and Setters. Only the possible functions are displayed. For example, if you already have setters for the available properties, only the getter option appears.

When you select Generate... Getter/Setter/Getter and Setter, a dialog appears with the properties for which you can generate a getter or setter. The properties are displayed in a tree. If you select a parent class, you automatically select all that class' properties.

You can name a getter or setter according to either the convention getName or the convention get_name.

For more information, see the following NetBeans PHP blog post: Overridden and Implemented Methods

You can generate overridden or implemented methods by pressing Alt+Insert (Ctrl+I on Mac) when the caret is inside a class declaration and there are multiple class members. A dialog opens showing the methods you can insert and indicating whether they are overridden or implemented.

This feature complements the "Implement all abstract methods" hint and code completion for overridden and implemented methods.

For more information, see the following NetBeans PHP blog post:

20.4.8 Defining Variable Type in Comments

You can define a variable and its type in a comment. The comment has to be in the format /* @var $variable type */ . If the comment is written correctly, the var tag is in bold font.

You can use the code template vdoc, followed by Tab, to generate a comment that defines a variable. The variable name is selected, and you can change it. Then press Tab again, and the type is selected.

The code template automatically sets the variable name and type. If a variable is used after the place where you insert the template, then that following variable name is suggested by default. If there is not any variable used after the place where you insert the template, but there is a variable used above the template, then that preceding variable name is suggested as default. If the IDE is not able locate any variable near where you use the template, then the default name is variable. The variable type is set automatically according to the same rules.

For more information, see the following screencast:

20.4.9 About PHP 5.4 Support

NetBeans Editor for PHP offers a number of features specific to developing with PHP 5.4, discussed in detail in the following blog entries:

20.5 How to Debug PHP Applications

Debugging is the process of examining your application for errors. The process of debugging is accomplished by setting breakpoints and watches in your code and running it in the debugger. This enables you to execute your code one line at a time or breakpoint-to-breakpoint and examine the state of your application in order to discover any problems.

When you start a PHP debugging session, a browser window opens. By default the application stops at the first line of the program. You must switch back to the IDE to continue the debugging session. You switch back and forth between the IDE and your browser throughout your debugging session.

Additional debugger windows also appear automatically at the bottom of your screen. These windows help you keep track of breakpoints, variables, sources, the call stack, and threads.

You can also debug applications that are running on a remote machine by setting up path mapping to a custom URL.

For more details see the following document:

20.5.1 Working with PHP Debugging

The following work flow shows how to debug a PHP project.

Set Up XDebug

  1. Determine if you have XDebug set up and configured.

  2. If you need XDebug, go to the XDebug web page and use their tools to determine what version of XDebug you should use.

  3. Download and install the correct version of XDebug according to their website.

  4. Configure the appropriate local php.ini file.

  5. Test XDebug in the command line.

  6. Configure the IDE to use XDebug.

For more information, see Section 20.5.2, "Setting Up XDebug."

Prepare to Debug

  1. Set breakpoints in your code. See Section 20.5.3, "PHP Breakpoints in the IDE."

  2. Set watches in your code. See Section, "Enabling and Creating Watches in PHP Code."

Begin a Debugging Session

  1. Start a local debugging session. For more information, see Section, "Starting a PHP Debugging Session."

  2. Debug a single file. See Section, "Starting a PHP Debugging Session."

  3. Set up path mapping for remote debugging. See Section, "Remote PHP Debugging and Path Mapping."

Monitor your Code

  1. Step through your code. See Section, "Stepping Through Your Program."

  2. View debugging information. See Section, "Viewing Variables When Debugging PHP Applications."

Finish the Debugging Session

To finish the current debugging session, or to finish one of several debugging sessions, see Section, "Finishing a PHP Debugging Session."

20.5.2 Setting Up XDebug

The IDE supports the XDebug third-party PHP debugger. If XDebug is installed correctly and the PHP environment is configured correctly, you can debug PHP projects inside the IDE. You can also debug PHP files remotely if you set up path mapping.

Additional information can be found in the following wiki document: Checking If XDebug Is Installed

The first step you should take is to see if XDebug is already installed on your system. Some AMP packages come with XDebug. Run phpinfo(). If there is an XDebug section in your PHP info, XDebug is installed. If XDebug is installed, Section, "Setting Up XDebug." Installing XDebug

The NetBeans IDE for PHP community consensus is that the XDebug installation wizard should be used to install XDebug.

  1. Run phpinfo().

  2. Copy the results of phpinfo() from your browser into the clipboard.

  3. In a browser window, open the following URL:

  4. Paste your PHP info into the XDebug wizard form and click Analyze.

  5. Follow the instructions that appear. Setting Up XDebug

The following section assumes you have XDebug installed and you need to set it up.

  1. Run phpinfo().

  2. In the PHP info, find the entries for Loaded Configuration File and Additional .ini Files Parsed.

  3. For each php.ini or xdebug.ini file you find, open that file and perform the following steps:

    1. Make sure the file contains the following settings:

      zend_extension=[path to xdebug .so or .dll]

      These settings are usually in a section labeled [XDebug]. If such a section does not exist, create one. However, some AMPs may differ. For example, in some versions of XAMPP AMP, the line zend_extension = "G:\xampp\php\ext\php_xdebug.dll" is outside of the [XDebug] section, and the name of the .dll file is nonstandard (php_xdebug.dll instead of xdebug.dll).

    2. Comment out all entries for Zend Optimizer, Zend Studio Debugger, or other Zend extensions. Testing XDebug

Before trying out XDebug from the IDE you should test your XDebug installation from the command-line. One way to test XDebug is to write a test in PHP and run a debug session on it.

  1. You need an arbitrary PHP file. If you do not have one, create a file called index.php, put any code into it and save it.

  2. Using a text editor, create a file called dbgtest.php and type or paste the following code into the file (save the file afterward):

    $address = '';
    $port = '9000';
    $sock = socket_create(AF_INET, SOCK_STREAM, 0);
    socket_bind($sock, $address, $port) or die();
    $client = socket_accept($sock);
    echo "Connection established: $client";

  3. Run the code from the command line (for example, /usr/bin/php dbgtest.php).

  4. Start a debug session for an arbitrary PHP file from within a browser window (for example, http://localhost/index.php?XDEBUG_SESSION_START=mysession).

If XDebug is properly configured, the script started in step 3 should print a message similar to "Connection established: Resource id #5". If no message is printed and the script is still running, XDebug is not properly configured or uses a different port or has another problem. In this case, kill the running process and investigate where the problem is. Setting Up Debugging Options in NetBeans IDE

After you install, configure, and successfully test XDebug, you can set up XDebug options in the IDE. To learn more about these options, open Tools > Options (NetBeans Preferences on Mac), go to the PHP Options, open the Debugging tab, and click Help.

20.5.3 PHP Breakpoints in the IDE

A breakpoint is a flag in the source code that tells the debugger to stop execution of the program. When your program stops on a breakpoint, you can perform actions like examining the value of variables and single-stepping through your program. Setting Breakpoints

Set a breakpoint for a line in your PHP code. To set a breakpoint, left-click the left margin or line number of the line. To remove the breakpoint, left-click the breakpoint icon.

The Source Editor indicates a line breakpoint by highlighting the line at which the breakpoint is set in red and placing an annotation in the left margin. Users of other languages supported in the IDE may be familiar with other types of breakpoints but only line breakpoints are supported in PHP projects at this time. For a table of breakpoint annotations that are used in the editor, see Section 9.8.5, "Managing Breakpoints."

You can view and organize all IDE breakpoints by choosing Windows > Debugging > Breakpoints (Alt+Shift+5). For details on organizing breakpoints, see Section, "How to Organize Breakpoints Into a Group."

20.5.4 Setting Current Context in the PHP Debugger

The current context is the portion of your program on which the debugger is currently focusing. When multiple sessions are running, only one session is current. Within the current session, the thread from which the debugger regained control is the default current thread. Inside the current thread, the most recent call is the default current call.

You can make any session, thread, or call current by right-clicking its node in the appropriate debugger window and choosing Make Current. Debugger Windows and Context

Most debugger windows depend on the current context. When you change the current context, the contents of these windows are updated to reflect the new context.

For example, the Debugging window shows the threads in the current session, while the Call Stack window shows the call stack for the current thread. The Variables window shows the variables that are local to the current call.

The exceptions are the Breakpoints and Watches windows. These windows list all breakpoints and watches set in the IDE. While the set of watches is shared by all sessions, an individual watch expression is evaluated and displayed based on the current context. The Source Editor and Context

When a variable is active in the current context, the Source Editor displays the value of the variable when you move the pointer over it. In cases where a program includes different variables with the same name, the Source Editor displays the value based on the current context, and not on the instance of the variable in the source code.

20.5.5 PHP Debugging Sessions

PHP debugging sessions use debugger windows inside the IDE. You can debug projects, or you can remotely debug Web pages. Starting a PHP Debugging Session

The IDE starts the debugger, then runs the application inside the debugger. When you start a debugging session, the IDE automatically opens the debugger windows, opens a browser window, and prints debugger output to the Output window. You start the debugging session in the browser window.

By default, the debugging session stops at the first line of the PHP code. You can disable stopping at the first line in the Debugging tab in the PHP category of the Options window. When the session stops, you have a number of options for stepping through/into or continuing the debugging session.

To start debugging a project:

  1. Locate the project's node in the Projects window.

  2. Either right-click the project node and select Debug, or select the project node and run the Debug Project command (Ctrl+F5).

Alternatively, you can debug an individual PHP file:

  1. Expand the project's node in the Projects window. Navigate the tree until you locate the file you want.

  2. Either right-click the file node and select Debug, or select the file node and run the Debug File command (Ctrl+Shift+F5).

The process for starting a debugging session is the same for local and remote projects. However, path mapping must be set up to debug remote projects. Remote PHP Debugging and Path Mapping

It is possible to debug both scripts and web pages, and web pages can be debugged either locally or remotely. For Remote Debugging, unfortunately the debugged php file on the remote server is not the same as the file opened in the IDE running on a local machine. Debugger support in the IDE must thus be able to map server paths to local paths. However, due to many complications, path mapping cannot be resolved automatically for every individual scenario. Therefore, you must manually define path mapping through the project setup for individual run configurations. You can also specify the proxy server, if any, and the URL at which the debugging session starts. If you do not specify this URL, debugging starts at your index file.

To set up path mapping and enable custom debugging URLs:

  1. Right-click the project's node in the Projects window and open the project's Properties from the context menu.

  2. In the Project Properties dialog, go to the Run Configuration category.

  3. Click the Advanced button. The Advanced Web Configuration dialog opens.

  4. Add the server path and the project path for path mapping.

  5. Under "Debug URL", select one of the following (do not leave the default selected):

    • Ask Every Time, which has the IDE prompt you for the URL when you start a debugging session.

    • Do Not Open Web Browser, which requires you to open the browser and enter the URL manually (you need the GET/POST XDEBUG_SESSION_START variable).

  6. If you are using a proxy server for debugging, enter the server's host name and port in the Debugger Proxy section.

For more information, please see the following post in the NetBeans for PHP blog: Stepping Through Your Program

By default, the debugging session stops at the first line of the PHP code. You can disable stopping at the first line in the Debugging tab in the PHP category of the Options window. When the session stops, you can step through your lines of code using the following commands on the Debug menu or toolbar:

You should set breakpoints before you start a debugging session or you will have to step over/into/out of your entire application. If you disable Stop at First Line and do not set any breakpoints, your application never stops during debugging and you get no useful results.

Command Shortcut Description

Debug > Continue


Runs the program until it reaches the next breakpoint or until the program terminates normally.

Debug > Step Over


Executes one source line. If the source line contains a call, executes the entire routine without stepping through the individual instructions.

Debug > Step Into


Runs the program to the next line and pauses execution before any changes have been made to the state of the program.

Debug > Step Out


Executes one source line. If the source line is part of a routine, executes the remaining lines of the routine and returns control to the caller of the routine. The completed method call is highlighted in the Source Editor.

Debug > Run to Cursor


Runs the program to the cursor location in the Source Editor and pauses the program. The file you have selected in the Source Editor must be called from the main class of the main project.

For more details, see the following document: Finishing a PHP Debugging Session

If necessary, you can stop the current debugging session using the Shift+F5 shortcut. You can also close a specific debugging session using the Sessions window.

To finish the current debugging session:

  1. Choose Debug > Finish Debugger Session (Shift+F5).

To finish one of several debugging sessions:

  1. Open the Sessions window by choosing Window > Debugging > Sessions (Alt+Shift+6).

  2. Right-click the debugging session you want to stop and choose Finish.

20.5.6 Using Debugger Windows with PHP

When you start a debugging session the IDE opens some debugging windows by default as tabs below the editor. You can open any debugger window by choosing Window > Debugging > window-name (for example, Window > Debugging > Breakpoints).

Each debugger window displays a variety of icons to relay information about the object. For example, the Breakpoints window uses a small red square to indicate a breakpoint set on a line. Some windows also include a node expansion control to the left of the icon. Clicking this control expands and collapses the object.

In the debugger tabs, information is organized into lists. Each list item represents a single object. Each column represents a property of the object. Data displayed in blue underlined text is linked to the source code.

Some elements of list in the debugger tabs have editable properties, such as the value property of a variable in the Variables window. If you select a property and the property has a white background you can edit the property. A selected property with a gray background cannot be edited.

You can move a column in a debugger tab by dragging the column header. You can click to the right of the column titles to open a dialog box that enables you to choose the columns that are displayed. You can right-click an item in the list to open a pop-up menu where you can choose to perform actions on that item and modify how the items are displayed in the tab. Using the Breakpoints Window

The Breakpoints window lists all the breakpoints that you set in your projects. You can open the Breakpoints window by choosing Window > Debugging > Breakpoints. If you open the Breakpoints window when a debugging session is running, it closes automatically when you end the debugging session. If you open the window when no debugging session is running, it stays open until you close it.

By default, each entry contains a short text description of the breakpoint and a checkbox indicating whether the breakpoint is enabled or disabled. You can enable or disable a breakpoint directly in the Breakpoints window by selecting or deselecting the checkbox. Icons

The icon to the left of the breakpoint summary indicates the type of the breakpoint.

Icon Description

Breakpoint icon

Breakpoint set on a specific line.

Invalid line breakpoint icon

Invalid line breakpoint.

Disabled breakpoint icon

Disabled breakpoint. Actions

The pop-up menu in the Breakpoints window includes the following items.

Menu Item Description

Go to Source

Finds the location of the selected breakpoint in the source code.


Turns off the selected breakpoint, but preserves an entry for it in this window.

Move Into Group

You can organize breakpoints into groups so that you can enable, disable, and delete the breakpoints as a group. You can select one or multiple breakpoints and then choose this option to create or add the breakpoints to a group. The group name is displayed as an expandable node in the Breakpoints window in the Custom Group view. You can also choose to display custom groups in the Nested view.

New Breakpoint

Creates a new breakpoint.

Enable All

Enables all the breakpoints in this window.

Disable All

Disables all the breakpoints in this window.


Deletes the selected breakpoint(s).

Note: If you choose this option, the breakpoint(s) is deleted immediately. There is no confirmation dialog box.

Delete All

Deletes all the breakpoints in this window.

Note: If you choose this option, all breakpoints are deleted immediately. There is no confirmation dialog box. Grouping Breakpoints

You can modify how breakpoints are organized in the Breakpoints window by clicking the Breakpoint Groups button and selecting a grouping strategy from the popup window. If you choose Nested you can specify the specific groups and the order of the groups that are displayed. Using the Call Stack Window

The Call Stack window lists the sequence of calls made during execution. When the debugger is suspended, the Call Stack window shows the sequence of function calls (that is, the call stack). On initial suspension, the top-most stack frame is selected automatically.

Double-click on a function call in the window to go to that line in the editor. If the call is made to a PHP class, the Navigator window will also go to that line when you double-click the call.

You can double-click on a call stack frame to select it, then explore any variable or expression values for that frame in the Variables and Watches windows. Icons

The following table describes the icons displayed to the left of the call name.

Icon Description

Current Call icon

The current call on the call stack.

Call Other Than Current icon

A call other than the current call. Using the Threads Window

The Threads window lists all threads in the current debugging session. You open the Threads window by choosing Window > Debugging > Threads.

The information given for each thread is the thread name, state and if the thread is suspended. One thread is the current thread. By default, the current thread is the thread in the current session from which the debugger gained control. When you select a different current session, the Threads window is updated to show the threads for that session. Using the Variables Window

The Variables window lists the local variables in the current call. By default, the Variables window opens automatically whenever you start a debugging session. You can open the Variables window by choosing Window > Debugging > Variables.

If you open the Variables window when a debugging session is running, it closes automatically when you end the debugging session. If you open the window when no debugging session is running, it stays open until you close it.

The information given for each variable includes the variable name, type, and value. You can click the control to the left of the name to expand or collapse the variable. If the object type is displayed in blue underlined text, clicking the text jumps to the object type in the source code. You can click the Value cell to edit the value directly in the Variables window.

In some cases, the debugger assigns a pound sign (#) and a number as the variable's value. This number is a unique identifier of the given instance. You can use this identifier to determine if a variable points to the same or to a different instance. You cannot edit this value. Properties

By default, all properties are displayed directly in the Variables window, except for the toString() property. To display the toString() property in the Variables window, right-click in the window and choose List Options > Change Visible Columns and then select the toString() checkbox in the dialog box. Using the Watches Window

The Watches window lists all variables and expressions that you have specified to watch while debugging. By default, the Watches window opens automatically whenever you start a debugging session. You can open the Watches window by choosing Window > Debugging > Watches.

If you open the Watches window when a debugging session is running, it closes automatically when you end the debugging session. If you open the window when no debugging session is running, it stays open until you close it.

The information given for each watch includes the variable or expression name, type, and value. If the variable has a control to its left, you can click the control to expand or collapse the object. If the object type is displayed in blue underlined text, clicking the text jumps to the object type in the source code. You can click in the Value cell to edit the value directly in the Watches window.

When you add a new variable or expression to the Watches window, the value of the variable or expression is immediately evaluated and displayed. The value of a watch is based on the current context. As you move through your program code, the Watches window is updated to show the value of the watch for that context.

In some cases, the debugger assigns a pound sign (#) and a number as the variable's value. This number is a unique identifier of the given instance. You can use this identifier to determine if a variable points to the same or to a different instance. You cannot edit this value. Properties

You can see all the properties for a watch by right-clicking the node for the watch and choosing Properties.

By default, all properties are also displayed directly in the Watches window, except for the toString() property.

20.5.7 Viewing Program Information

While debugging PHP applications, you can view two types of programming information:

  • variables, either in the variables window or in the source editor

  • watches, which are mechanisms for observing the changes in the value of a variable or expression during execution. Viewing Variables When Debugging PHP Applications

In the IDE, local variables are listed in the Variables window, however it is also possible to evaluate variables directly in the Source Editor.

Using the Variables Window

For each variable within the current call, the Variables window displays information including the variable name, type, and value. The Variables window also displays all of the static fields from the present class and all superclasses for each variable, as well as all of the inherited fields from all superclasses.

You can change the value of a local variable directly in the Variables window and then continue running your program with the new value in place.

In some cases, the debugger assigns a pound sign (#) and a number as the variable's value. This number is an unique identifier of the given instance. You can use this identifier to determine if a variable points to the same instance or to a different instance. You cannot edit this value.

Evaluating Variables in the Source Editor

You can also evaluate a variable directly in the Source Editor by moving the insertion point over the variable. If the variable is active in the current context, the value of the variable is displayed in a tool tip. In cases where a program includes different variables with the same name, the Source Editor displays the value based on the current context, and not on the instance of the variable in the source code.

You can track the changes in the value of a variable during program execution by setting a watch on the variable. When you create a watch, the value of the variable is immediately evaluated and displayed in the Watches window. Enabling and Creating Watches in PHP Code

A watch enables you to track the changes in the value of a variable or expression during program execution. The Watches window lists all of the watches you defined for all IDE projects, of all programming languages. You can open the Watches window by choosing Window > Debugging > Watches (Alt+Shift+2).

Watches can destabilize XDebug, especially if a watch is set on invalid code.

Before you can set watches in PHP code, you must enable PHP watches.

To enable watches for PHP:

  1. Open Tools > Options (NetBeans Preferences on Mac).

  2. Click the PHP icon.

  3. Open the Debugging tab.

  4. Select Watches and Balloon Evaluation.

  5. Optionally, change the Maximum Depth of Structures and/or the Maximum Number of Children. These numbers set the visibility of nested structures and array items, respectively, during Watch evaluation.

  6. Click OK.

For more information about PHP Debugging Options, click Help at the bottom of the Debugging tab.

If watches and balloon evaluation is enabled in PHP Options, you can create watches in the Source Editor.

To create a watch from the Source Editor:

  1. Select the variable or expression in the Source Editor, right-click, and choose New Watch (Ctrl+Shift+F7).

    The New Watch dialog box opens with the variable or expression entered in the text field.

  2. Click OK.

The Watches window opens with the new watch selected.

For more details, see the following document:

20.6 Using a Continuous Build Server With PHP

The IDE supports creating and starting build jobs using the Hudson build server. Hudson's usefulness for PHP projects is that it allows PHPUnit tests to be performed automatically according to a schedule.

For more information about setting up and using a Hudson build server, see the following documents:

The Jenkins build server should also work with the IDE, though this is not so thoroughly tested.

Hudson is usually run on a remote machine. This section contains information for the administrator of the Hudson or Jenkins host machine.

In order for Hudson (or Jenkins) to be used with PHP and to provide test results, the Hudson or Jenkins server should be set up with the plugins described on the web page. (Hudson has equivalent plugins.) The host machine for the Hudson or Jenkins server should also have PHP and PEAR installed with the PHP plugins listed on the Template for Jenkins Jobs for PHP page.

To add a Hudson instance:

  1. Right-click the Hudson Builders node in the Services window and choose Add Hudson Instance.

  2. Type the Name for the instance that will be displayed under the Hudson Builders node.

  3. Specify the server URL, the auto-refresh setting. Click Add.

In most cases Hudson is run on a remote machine. The administrator of the remote machine provides you with the URL.

After you add a Hudson instance, a node for the instance is added below the Hudson Builders node. You can expand the node to view the status of builds on that instance.

For a PHP project to build on Hudson, the project must have the following set up:

You also need to have PhpProject Wizard (PPW) installed on your local machine. Use PEAR to install PPW. See the PHP Project Wizard page at

You can then set PHP Options for Hudson.

To set PHP options for Hudson:

After PHP options are set you can proceed with setting up a new build job.

To set up a new build job:

  1. Choose Team > Create Build Job from the main menu. Alternatively, in the Services window, right-click the Hudson instance you want to use and choose New Build.

  2. Select the build server instance from the dropdown list.

  3. Specify the name for the build job.

  4. Select the project from the dropdown list.

    The build server will use the sources in the project's repository.

  5. Click Create. The IDE generates build.xml and phpunit.xml.dist files in the project.

  6. Commit the project's new build.xml and phpunit.xml.dist files in your version control system.

After you supply the details for the build, you can start the build process on the server by right-clicking the build that you want to start and choosing Start Job. When a job is building, the node for the job is displayed as running. You can expand the node for the job to view past builds and build artifacts.

To create builds and start jobs you must have access to a Hudson server. For more information on Hudson, see the Hudson wiki at