Uniform Server PHP IDE: XDebug WinBinder

Revision as of 11:24, 2 December 2010 by Ric (talk | contribs) (New page: {{nav Uniform Server PHP IDE}} '''''How to XDebug WinBinder''''' WinBinder is an open source extension for PHP allowing you to easily build Windows applications. A WinBinder application i...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

 

MPG UniCenter

Uniform Server PHP IDE.

How to XDebug WinBinder

WinBinder is an open source extension for PHP allowing you to easily build Windows applications. A WinBinder application is essentially a PHP CLI script and therefore is debuggable using XDebug and a suitable client.

Our PHP IDE (Notepad++, DBGp client and console) has the capability of debugging a WinBinder application. On the IDE Overview page I mentioned on occasions you need to use a real command window this is such a scenario. A WinBinder application needs to be detached from the IDE hence the internal console cannot be used.

This page looks at debugging a simple window application created using WinBinder.

Note: Assumes you have installed Uniform Server PHP IDE portable.

Preliminary

Location of test files

  • H:\us_ide_1\us_portable_php_ide\php_scripts\winbinder_example.phpw – Test script
  • H:\us_ide_1\us_portable_php_ide\php_scripts\winbinder_no_debug.bat – Runs test script
  • H:\us_ide_1\us_portable_php_ide\php_scripts\winbinder_debug.bat – Runs test script
  • H:\us_ide_1\us_portable_php_ide\php_scripts\winbinder\include – WinBinder include files

Note: Your paths will be different substitute as appropriate.

Disable default break point

Debugging a WinBinder script requires disabling the default break-point

in client configuration as follows:


  • Start IDE: Double click on file Run_IDE.bat


Disable default break point

  • Open DBGp configuration window Plugins>DBGp>Config...
  • Step D) Un-Check Break at first line when debugging starts
    • Leave all other settings as they are
  • Step E) Click OK


Start Debug Window:

  • Click Debugger icon opens debug window

 

WinBinder test script

Test script winbinder_example.phpw creates a window with two buttons. They both produce an alert box displaying different information.

Script contains a break point function xdebug_break() currently commented out. We will enable this later to debug function test()

<?php
include "winbinder/include/winbinder.php";  // Location of WinBinder library
$mainwin = wb_create_window(NULL, AppWindow, "US Test",WBC_CENTER, WBC_CENTER, 320, 240, WBC_TOP);
wb_create_control($mainwin, PushButton, "Button 1",  50, 70, 80, 22,     101);
wb_create_control($mainwin, PushButton, "Button 2", 180, 70, 80, 22,     102);
wb_set_handler($mainwin, "process_main");
wb_main_loop();
function process_main($window, $id) {
 switch($id) {
   case 101:
// xdebug_break();
     test($window,$id);
     break;
   case 102:
     wb_message_box($window, "Button #$id was pressed.");
     break;
   case IDCLOSE:                  // The constant IDCLOSE is predefined
     wb_destroy_window($window);  // Destroy the window
     break;
 }
}
function test($window,$id){
 $a= 10;
 $b= 20;
 $c= $a + $b;
   wb_message_box($window, "Button #$id was pressed \n Result = $c.");
}
?>

Top

Batch Files

There are two batch files:

winbinder_no_debug.bat

Runs test script with no debugging. Demonstrates what the application does.

Quick check:

Double click on winbinder_no_debug.bat runs test script. Click both buttons an alert box pops-up. Close these and then the main window.

mode con:cols=65 lines=20
TITLE UNIFORM SERVER - Winbinder No Debug
COLOR B0
@echo off
cls

..\unicode\php\php.exe -c ..\unicode\php\php_cli_ide.ini winbinder_example.phpw

pause

winbinder_debug.bat

This uses a PHP configuration that loads XDebug for debugging test script.

Quick check:

Double click on winbinder_debug.bat runs test script. Notepad++ icon flashes. Click both buttons an alert box pops-up. Close these and then the main window.

mode con:cols=65 lines=20
TITLE UNIFORM SERVER - Winbinder With Debug
COLOR B0
@echo off
cls

..\unicode\php\php.exe -c ..\unicode\php\php_cli_ide_debug.ini winbinder_example.phpw

pause

Although communication is established between XDebug and client no debugging takes place. To enable debugging at least one break-point must be set.

Top

Set break-point and Debug

Enable break-point

  • Edit script winbinder_example.phpw
  • Remove comments from function xdebug_break() this enables the break-point.

Debug

  • Now run the script using winbinder_debug.bat
    • Notepad++ icon flashes.
    • There is no text in the edit window or any debug information.
  • Click Button 2
    • Again no debug information only a button response.
  • Click Button 1
    • Edit window displays winbinder_example.phpw
    • Green arrow pointing to break-point function.
    • Debug window is active
    • Clicking Step into allows you to step through button 1 code.
<?php
include "winbinder/include/winbinder.php";  // Location of WinBinder library
$mainwin = wb_create_window(NULL, AppWindow, "US Test",WBC_CENTER, WBC_CENTER,
 320, 240, WBC_TOP);
wb_create_control($mainwin, PushButton, "Button 1",  50, 70, 80, 22,     101);
wb_create_control($mainwin, PushButton, "Button 2", 180, 70, 80, 22,     102);
wb_set_handler($mainwin, "process_main");
wb_main_loop();
function process_main($window, $id) {
 switch($id) {
   case 101:
  xdebug_break();
     test($window,$id);
     break;
   case 102:
     wb_message_box($window, "Button #$id was pressed.");
     break;
   case IDCLOSE:                  // The constant IDCLOSE is predefined
     wb_destroy_window($window);  // Destroy the window
     break;
 }
}
function test($window,$id){
 $a= 10;
 $b= 20;
 $c= $a + $b;
   wb_message_box($window, "Button #$id was pressed \n Result = $c.");
}
?>

Top

Summary

That concludes this IDE introduction.

Top