I have just started learning php-gtk 2 but am a bit stuck. First is that are there any php-gtk 2 debuggers or error loggers that I can use because at the moment, if there is a bug in my script, the exported exe file made from my php-gtk script is simply currupted or won't open. So does any body know of such program to read my script and tell if there are bugs and what roughly lines the bugs are on. Note: This is php-gtk - not plain php.

Also I have encountered a multi object problem where only the first button will be displayed on the screen. Below is the code I am using and do you know why the button $button2 wont show.

<?php
 
function pressed()
{
    echo "Hello again - The button was pressed!\n";
}

function pressed2()
{
    echo "Hello again - The button was pressed!\n";
}

 
$window = new GtkWindow();

$window->resize(800,600);
$window->set_title('My Diary');
$window->connect_simple('destroy', array('Gtk', 'main_quit'));


$button1 = new GtkButton('Jan');
$button1->connect_simple('clicked', 'pressed');
$button1parrent = new GtkAlignment(0, 0, 0.01, 0.01);
$button1parrent->add($button1);
$window->add($button1parrent);



$button2 = new GtkButton('February');
$button2->connect_simple('clicked', 'pressed2');
$button2parrent = new GtkAlignment(0, 0, 0.01, 0.01);
$button2parrent->add($button2);
$window->add($button2parrent);


$window->show_all();
//$window->set_resizable(false);
Gtk::main();
 
?>

In case if you are wondering what php-gtk is, it is like php but with more libraries/binaries and instead of creating webpages, it creates programs.

I've fixed your code:

<?php 

if (!class_exists('gtk')) {
    die("Please load the php-gtk2 module in your php.ini\r\n");
}

function pressed()
{
    echo "Hello again - The button was pressed!\n";
}

function pressed2()
{
    echo "Hello again - The button was pressed!\n";
}

 
$window = new GtkWindow();

$window->resize(800,600);
$window->set_title('My Diary');
$window->connect_simple('destroy', array('Gtk', 'main_quit'));


$button1 = new GtkButton('Jan');
$button1->connect_simple('clicked', 'pressed');
$button1parrent = new GtkAlignment(0, 0, 0.01, 0.01);
$button1parrent->add($button1);



$button2 = new GtkButton('February');
$button2->connect_simple('clicked', 'pressed2');
$button2parrent = new GtkAlignment(0, 0, 0.01, 0.01);
$button2parrent->add($button2);


$buttonbox = new GtkVButtonBox();    // or GtkHButtonBox for horizontal placement
$buttonbox->add($button1parrent);
$buttonbox->add($button2parrent);


$window->add($buttonbox);

$window->show_all();
//$window->set_resizable(false);
Gtk::main();
 

?>

I'm learning php-gtk too :) It seems like is mandatory to enclose UI elements into boxes before adding to GtkWindow.

I recommend to read this serie of tutorials:

http://gtk.php.net/manual/en/tutorials.packing.php

Yes, It works.
Thanks. My current code is below and displays a row of buttons at the top. The only other thing I need to know is if there is any software that will display the error messages from any errors in my php file. I have tried enabling error reporting in the php.ini file of the compilation but makes no difference but other than that it works great and love the tutorials you linked to.

Below code does the job:

<?php 
 
if (!class_exists('gtk')) {
    die("Please load the php-gtk2 module in your php.ini\r\n");
}
 
function pressed()
{
    echo "Hello again - The button was pressed!\n";
}
 
function pressed2()
{
    echo "Hello again - The button was pressed!\n";
}
 
 
$window = new GtkWindow();
 
$window->resize(800,600);
$window->set_title('My Diary');
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
 

$button1 = new GtkButton('January');
$button1->connect_simple('clicked', 'pressed'); 
 
$button2 = new GtkButton('February');
$button2->connect_simple('clicked', 'pressed2');

$button3 = new GtkButton('March');
$button3->connect_simple('clicked', 'pressed2');

$button4 = new GtkButton('April');
$button4->connect_simple('clicked', 'pressed2');

$button5 = new GtkButton('May');
$button5->connect_simple('clicked', 'pressed2');

$button6 = new GtkButton('June');
$button6->connect_simple('clicked', 'pressed2');

$button7 = new GtkButton('July');
$button7->connect_simple('clicked', 'pressed2');

$button8 = new GtkButton('August');
$button8->connect_simple('clicked', 'pressed2');

$button9 = new GtkButton('September');
$button9->connect_simple('clicked', 'pressed2');

$button10 = new GtkButton('October');
$button10->connect_simple('clicked', 'pressed2');

$button11 = new GtkButton('November');
$button11->connect_simple('clicked', 'pressed2');

$button12 = new GtkButton('December');
$button12->connect_simple('clicked', 'pressed2');


$buttonbox = new GtkHButtonBox();    // or GtkHButtonBox for horizontal placement 
$buttonbox->add($button1);
$buttonbox->add($button2);
$buttonbox->add($button3);
$buttonbox->add($button4);
$buttonbox->add($button5);
$buttonbox->add($button6);
$buttonbox->add($button7);
$buttonbox->add($button8);
$buttonbox->add($button9);
$buttonbox->add($button10);
$buttonbox->add($button11);
$buttonbox->add($button12); 
$buttonboxparrent = new GtkAlignment(0, 0, 0.01, 0.01);
$buttonboxparrent->add($buttonbox);

 
$window->add($buttonboxparrent);
 
$window->show_all();
//$window->set_resizable(false);
Gtk::main();
?>

I'm using the php executable from Terminal to load the php-gtk code (located in /usr/local/php-gtk in my Mac OS 10.5 after installing this DMG package).

Before compiling the code you can perform php -l code_example.php to check for syntax errors (maybe, we can do it automatically from the editor assigning a macro or menu function). In Windows should work exactly as described here, also it's possible to perform and interpret the code, showing errors and output messages on the MS-DOS prompt using directly php code_example.php alone without -l parameter.

I'm using the php executable from Terminal to load the php-gtk code (located in /usr/local/php-gtk in my Mac OS 10.5 after installing this DMG package).

Thanks for the advice and it is the information in that statement that allowed me to find out how to run the debugger. And since I have 2 computers, instead of installing the official software twice (I like the unofficial stuff) I simply just copied the 2 files (php.exe and php5ts.dll) from the computer with the official software to a selected directory in the computer without the official software where I could use a batch file to do the hard work. I then placed in my batch file the below commands and it works like a charm.

@echo -
@php -l index.php
@echo -------------------------------
@pause

Pitty this isn't obvious to find on the internet.
So *Solved*

Also, this modification can be useful adding an argument to the ms-dos, avoiding copy&paste each file name:

@echo off
echo -
php -l %1
echo -------
pause
This question has already been answered. Start a new discussion instead.