# PHP-GTK an alternative to Java?

I experimented a little with PHP-GTK yesterday. I have massive amounts of PHP-libraries lying around and didn't want to switch to another language for using those libraries in other applications than pure web.

The combo of PHP and GTK makes up for a reasonable alternative (for java for example) for platform independent applications. Especially if combined with libglade. Glade is a tool which is used to build graphical interfaces and store this in a XML format. PHP-GTK is able to read those XML-files and dynamically build the interface. This way, the interface is separated nicely from the code and can be changed without changing the code. :-))

Example:

 1  <?xml version="1.0"?>
2  <GTK-Interface>
3    <widget>
4      <class>GtkWindow</class>
5      <name>windowMain</name>
6      <width>150</width>
7      <height>80</height>
8      <title>PHP-GTK-Glade for world domination</title>
9      <type>GTK_WINDOW_TOPLEVEL</type>
10      <position>GTK_WIN_POS_NONE</position>
11      <modal>False</modal>
12      <allow_shrink>False</allow_shrink>
13      <allow_grow>True</allow_grow>
14      <auto_shrink>False</auto_shrink>
15      <widget>
16        <class>GtkButton</class>
17        <name>button</name>
18        <can_focus>True</can_focus>
19        <signal>
20          <name>clicked</name>
21          <handler>on_button_clicked</handler>
22        </signal>
23        <label>Exit</label>
24        <relief>GTK_RELIEF_NORMAL</relief>
25      </widget>
26    </widget>
27  </GTK-Interface>

And the code

1  function on_button_clicked() {
2      echo "Clickedn";
3  }
4
5  $$gx = &new GladeXML('interface.glade'); 6$$gx->signal_autoconnect();

This creates a window with a button on it and connects the clicked signal to the function on_button_clicked . With minimal effort this application can be deployed on any platform which supports PHP and GTK. (someone else may figure out how many, but lots).

Because the glade interface is in XML this can be deployed locally or remotely at will. For PHP we know that it can run both locally and on the server. This combined opens up some interesting possibilities. We now can deploy interface and code both locally and remotely.

The usual goodies which relate to XML are of course applicable to glade, like for example XSLT transformations on the interface file (for example filtering out interface elements which have no usefull meaning due to privilege restrictions).

The combo opens up interesting options for bringing desktop applications and web applications closer together. The whole suite reminds one of techniques used in XUL applications and of Java deployment strategies. I gather if we could hook up this combo to an object broker service like Corba and a PHP compiler we'd have a very powerfull platform.

It certainly warrants further investigation.