|
|
 |
|
|
 |
Breakpoints in PHP Debugger
|
Using Breakpoints in PhpED is quite straightforward:
- You can set the Breakpoints in the source opened in PHP Editor
- To edit Breakpoints properties, go to View->Debugger Window->Breakpoints.
- View->Debugger Window->Breakpoints is also used to set Global Breakpoint
However sometimes we get the questions about Breakpoints and PHP Debugger. These are FAQ about Breakpoints. Before going any further we strongly recommend to run Project Setting Wizard in your Project - it helps to resolve the Breakpoint issues 7 out of 10 times.
Why do my Breakpoints not work?
You set the breakpoint, but PHP Debugger doesn't stop at it. What could be wrong? Here are the most common causes:
- The issue that we came across quite a few times: breakpoints are set, but the script is started in the Run mode instead of Debug. Breakpoints are only working when you are running the scripts in Debug mode, because Breakpoints are the feature of PHP Debugger session only.
- Also, very common issue: breakpoints are set on non-executable lines. PHP interpreter processes the source and generates stop-points for certain lines of PHP code. These lines have a blue dot next to them in PHP Editor. Sometimes counter-intuitive but true that some lines of your PHP code will not have these blue dots next to them, even though you might think they should. For example: long statements taking more than one line won't have the blue dots inside. Another example is if/ and if/else, statements without the curly brackets - then and else will be missing the blue dots as well. Another potential "gottcha" for breakpoints is switch($variable) statements - switch will not have a blue dot next to it. However, $myclass->mymethod()) or switch($myfunc()) or even switch($var1=$var2) will be considered stop-lines because there is an executable code located in them. Such are the features of PHP itself - PhpED just follows the instructions of PHP engine
|
 |
|
- Another issue: breakpoints are set in the file that is not currently executed by PHP Debugger and not included in other PHP scripts executed by the debugger. "It is hard to look for a gray cat in the dark room. Especially if it is not there"
- Similar to above but trickier use case: Breakpoints are in the file, which is run after the current http request ended - for example Ajax. NOTE: if you have debug session checked in Tools->Settings->Run & Debug, then the scripts will continue to run in Debug mode after the request is done and your breakpoints will be hit. But if debug session is off, then all subsequent scripts will not be running in regular Run mode and the breakpoints will have no effect. Please see Troubleshooting section below for more information about this use case
What are the best practices for using Breakpoints in PhpED?
- Set your breakpoints at the beginnings of the statements (on the blue dots). This way you will be sure that PHP generated stop-point in the place where your breakpoint is situated. If you are not sure where blue dots will be generated you can start the debugging with step-in and step through to the file where you want to set the breakpoints. When you hit the code where your file is included, the blue dots will be generated for your file.
- Quite often it is easier to start debugging by using NuSphere Browser Debugger Toolbar.
You can open the web site in an external browser, navigate to the needed page and click Debug in debugger toolbar of the browser (please see View -> Toolbars -> NuSphere Toolbar in the browser menu)
Troubleshooting of Breakpoints
If you are sure that the file with breakpoints is being executed but the breakpoints are still not working, chances are your file is being executed in the request different from your original debugger request and debug session is turned off. Firstly - turn on the debug session and check again. Other thing to watch for once the debug session is turned on:
- Check that the request to the file is on the same URL as the debugger request, with the same hostname and the same protocol. Switching from http to https will break the debug session! You can learn about debugging multiple domains here: http://www.nusphere.com/kb/technicalfaq/howto_run_dbg.htm
- Next - check that the cookies are enabled. Without the cookies debug session doesn't work.
|
|
|
|  |
|