Debugging Magento Code with NetBeans 6.8 Beta

Well, I’m sure you are aware of how the xdebug is used on debugging PHP applications. However there can be people out there, alone, killing their eyes trying to find out which class called which functions etc. Here is a quick tip for you! Especially if you are trying to find your way with Magento like I do!

As I had mentioned earlier, NetBeans is a great IDE with it’s support to PHP! PHP debugging is around for sometime and used by commercial PHP IDEs like Zend Studio or Komodo or equivalent. With the emergence of Eclipse PDT, NetBeans and of course xdebug, we can freely and easily debug our PHP applications. However as the web evolved, there are not anymore php files to debug but there are “user friendly” urls to debug. So you cannot give the filename to NetBeans and say debug! because most of the web applications out there are now MVC based as this is the new trend in the PHP world. MVC means, one file -index.php dispatches all the requests. So how to debug using friendly urls.

Well you can use your NetBeans IDE to listen requests coming from your browser. That’s what NetBeans does when you click on debug button, which opens the start page (index.php) with a get variable like: ?XDEBUG_SESSION_START=netbeans-xdebug. This value (netbeans-xdebug) can change from your NetBeans configuration (click on preferences and choose the PHP tab). When this parameter is given, you can send any request to the NetBeans and it will listen!

Let’s cut the crap and problem definition and come to the solution: All you need to do:
1. Start the debugging session on clicking Debug button

2. Continue until the end of the script however do not finish the debugging session by clicking on the Stop button.

3. On you browser, write the url you want (http://localhost/magento/customer/account/login/)

4. Add your own debugger identifier to the end of it like: index.php?XDEBUG_SESSION_START=netbeans-xdebug (For magento use http://localhost/magento/customer/account/login/XDEBUG_SESSION_START/netbeans-xdebug, notice that I’m first adding the key and value next to the end of the url)

5. Check your NetBeans to see that your new request is already started to be debugged! Now you can walk around the code and debug it anyway you like it.

That’s All Folks! It really helped me and I hope it helps you too.