views:

892

answers:

3

I am using Symfony (1.31) - with Propel ORM to build a website. I have recently moved from using a text editor, to Netbeans (6.8) as my dev environment.

Coming from a compiled language (C++) background, I am used to setting break points in code etc as part of debugging. Web development I have encountered (atleast with PHP), has been largely hit and miss - well debugging has been messy to say the least, using echo statements, logging stuff to file etc. Well I hear that it is possible to debug PHP (i.e. set breakpoints etc).

I have scoured the net for documentation to show how to set breakpoints (say in one of the MVC layesrs) so that when the relevant page(s) is opened via a browser, the breakpoint will get hit and I can step through the code (ideally, watching the program variables).

Is this possible using Symfony and Netbeans 6.8?.

A: 

I've used Gubed with Quanta+ as a stepping debugger with PHP, don't know if you can get that to work with Netbeans but I thought it was more hassle that it was worth. I found that I could for(i=0;i<~6;i++){dump stuff to screen/log; make changes; reload;} and solve an issue in less time than it took me to step through it once with the debugger.

Xdebug is a very useful PHP extension which features a remote debugger with support for some editors, though Neatbeans isn't listed. I've not used the remote debugging element of Xdebug (see above) but the profiling, code coverage and - in particular - improved browser error messages I find helpful.

Generally with Symfony I find I can get most of what I need from stack traces or by dropping items into the logger and picking them up with either the debug toolbar or firesymfony.

Colonel Sponsz
+1  A: 

Here is what has helped me debug my Symfony apps:

Enable logging and the web debug toolbar via apps/appname/config/settings.yml. Note: Any changes will require clearing the cache.

dev:
    .settings:
        web_debug:              true
        logging_enabled:        true

Use var_dump() or print_r() with pre tags to dump data from anywhere. Adding exit; will allow you to dump variables from the controller or anywhere else.

echo '<pre>';
vardump($something);
echo '</pre>';
exit;

Enable logging and log messages. You can access the logger anywhere as well, but make sure you enable logging for your environment:

sfContext::getInstance()->getLogger()->info($message);
markb
+1  A: 

There seems to be support for XDebug: http://netbeans.org/kb/docs/php/debugging.html

If you have specific questions about configuring XDebug: http://wiki.netbeans.org/HowToConfigureXDebug.

More useful articles on PHP development in NetBeans: http://netbeans.org/kb/trails/php.html.

Hope that helps.

UPDATE: Just installed NetBeans 6.8 and ran through the configuration and was able to get breakpoints to work successfully with XDebug. NetBeans' integration with Symfony is pretty slick too, +1 to question for getting me to check this out.

Cryo
Cyro, can you give a quick outline here to explain how you got the breakpoints to work with Symfony, Netbeans and XDebug?. Also, what kind of test did you run (i.e. did you test it like I described - i.e. set a breakpoint, and open a page?). I look forward to your response, as I am really hoping to be able to do this.
Stick it to THE MAN
Install XDebug for PHP 5.2 with WAMP. Add configuration to php.ini and restarted Apache. Checked phpinfo() to make sure it was being loaded (search for "xdebug"). Added test echo statement to index.php web controller. Set my project to Main Project. Pressed Ctrl+F5 to start debugging. NetBeans launches my Project URL in my browser but the page is waiting, go back to NetBeans and it's in debug mode. Press continue (F5) to push execution to my breakpoint. Now NetBeans is at my breakpoint and I can view Watches, Variables and Call Stack tabs for more info or step into my code. That's it.
Cryo
I just tested it with a breakpoint in a specific action as well and it works there too. Once you're in debug mode visit your action URL with the breakpoint and be sure to append ?XDEBUG_SESSION_START=netbeans-xdebug after the URL and NetBeans should pick it up from the beginning of the request.
Cryo