|
Every program no matter how well written can have bugs or other defects - there's no exception to this rule, including in your PHP scripts or any other software program that you develop. Debugging is the process of finding the bugs so they can be fixed and the PHP Debugger is the best tool for helping you find the bugs fast and eliminate them from your PHP programs. You can setup remote debugging in PhpED with the help of DBG Wizard. For information about the following: location of PHP Debugger modules, which module to use, and how to install it please click here.
How to debug a PHP script
|
There are many techniques used for PHP debugging, varying from desperate PHP code inspection to angry keyboard slamming. A less extreme and more useful approach would be to use print statements and logging embedded in your PHP code, printing out variable values throughout various stages of the program execution.
|
 |

click to enlarge
|
This approach works well in general, however suffers from several drawbacks, for example:
- It requires significant additional coding effort, which ironically can introduce even more bugs into your php script
- Debugging of PHP with print statements is a highly repetitive process - it's impossible for a developer to lock onto a problematic region of code while printing everything and everywhere
- Introduction of so many print statements and conditional can affect the performance of your PHP application.
PhpED's PHP Debugger provides a powerful and easy way to simplify PHP debugging because it gives you complete visibility and control over the execution of PHP scripts and doesn't require that you make any changes to your PHP code. With PhpED's PHP Debugger you can:
- Step through lines of php code
- Inspect any variable or class in PHP
- Assign a different value to PHP variables in the script
- Set break points to interrupt php script execution
- Make these break points act based on various conditions
- Call a PHP function on the fly and inspect the results
- Set break points dependant on Global True Expression
- Jump to a different line of PHP code
- Inspect the traceback of the execution (aka see the stack)
- Support for remote PHP debugging
- Absolutely secure debugging with SSH
How to use PhpED's PHP Debugger
PhpED's PHP Debugger will let you step through your php code, control the execution flow, see the current values of all variables in the script as well as content of the arrays and classes at each stage or even assign different values to the variables on the fly and do all of it without making any changes to php application. This brief tutorial will help you to learn how to use PhpED's PHP Debugger.
Step through lines of php code
PhpED's PHP Debugger lets you step through the execution of a php scripts, line-by-line, just as you would using a conventional software debugger. Using the PhpED Debugger toolbar, you can:
- Step-In: Execute the next line of php code.
- Step-Out: Return to the line of php code that called the function you are in.
- Step-Over: Execute the current line of php code.
Single-Stepping through a PHP script is illustrated here:
|
 |

click to enlarge
|
Inspect any variable or class in PHP
PhpED's PHP Debugger three ways to see the values of the variables or the members of the PHP class.
- The value of the variable is shown when the cursor is hovered over the variable in PHP code
- The values of the Local variables and classes are displayed in Locals tab of PhpED debugger
- The values of the Global variables and classes are displayed in Globals tab of PhpED debugger
- Variables and classes added to the Watch tab of PhpED debugger and displayed there
The content of Locals, Globals and Watch tabs changes as you step through the code.
|
 |

click to enlarge

click to enlarge
|
Assign a different value to PHP variables in the script
|
The PhpED PHP Debugger will let you assign a different value to any PHP variable. This feature allows you test your fix before you change the actual PHP code in the script.
|
 |

click to enlarge
|
Set/toggle break points to interrupt php script execution
|
PhpED allows you to easily set and toggle breakpoints anywhere in your PHP code (illustrated below). The lines of code highlighted in blue represent breakpoints. The line in red shows the PHP script current state. You can set/toggle breakpoints from a toolbar, by typing the "F5" key, or by clicking on the red dot to the left of the line of code.
|
 |

click to enlarge
|
Call PHP function on the fly and inspect the results
|
Using Immediate tab of PhpED debugger you can call any php function on the fly in the middle of the execution of your PHP script. Simply type in the function call in the window and press Enter. The functionality of Immediate tab is illustrated below:
|
 |

click to enlarge
|
In this tutorial you learned about the many features of the PHP Debugger and how to use them to quickly find and eliminate bugs from your PHP scripts. You can watch a live demonstration of using the PHP debugger and advanced remote PHP debugging from our video tutorial library. Additional technical information is available on the NuSphere Support Forum. Download a free trial of our PHP Debugger today!
|