By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Problem in PHP-GTK application

P: n/a
Hi,
I m vishal jayaswal. I m doing my BE from Agra and i m working on PHP.
At present i m creating an small application for adding two numbers.
Enter forst number in one text box and second number in other text
box. When you click the button Result, sum of both the number thta are
entered in both the text boxes, shown in result text box. but this
code create an error when i run this code:

<?
if (!class_exists('gtk'))
{
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
dl('php_gtk.dll');
else
dl('php_gtk.so');
}
function delete_event()
{
return false;
}
function destroy()
{
Gtk::main_quit();
}
function result($button, $window)
{
$gettext1 = $ent1->get_text();
$gettext2 = $ent2->get_text();
$result = $gettext1 + $gettext2;
$ent3->set_text($result);
}
function test1()
{
global $window;
global $ent1;
global $ent2;
global $ent3;
$window->destroy();
}
$window = &new GtkWindow();
$window->set_name('Main Window');
$window->set_title('Introduction to PHP-GTK');
$window->connect('destroy', 'destroy');
$window->connect('delete_event', 'delete_event');
$window->set_border_width(5);
$window->set_position(GTK_WIN_POS_CENTER);
$frame = &new GtkFrame('Calculator');
$window->add($frame);
$table = &new GtkTable(3, 2, false);
$frame->add($table);
$num1 = &new GtkLabel('Number1: ');
$num2 = &new GtkLabel('Number2: ');
$ent1 = &new GtkEntry();
$ent2 = &new GtkEntry();
$ent3 = &new GtkEntry();
$button = &new GtkButton('Result');
$button->connect('clicked', 'result', '$window');
$table->attach($num1,0,1,0,1);
$table->attach($num2,0,1,1,2);
$table->attach($button,0,1,2,3);
$table->attach($ent1,1,2,0,1);
$table->attach($ent2,1,2,1,2);
$table->attach($ent3,1,2,2,3);
$window->show_all();
Gtk::main();
?>

Error Occured:

C:\php4>php c:\php4\test\test1.php
Fatal error: Call to a member function on a non-object in
c:\php4\test\test1.php
on line 23

Please send me the solution of this problem.
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
bi***********@yahoo.com (Vishal Jayaswal) wrote in
news:ba*************************@posting.google.co m:
Hi,
I m vishal jayaswal. I m doing my BE from Agra and i m working on PHP.
At present i m creating an small application for adding two numbers.
Enter forst number in one text box and second number in other text
box. When you click the button Result, sum of both the number thta are
entered in both the text boxes, shown in result text box. but this
code create an error when i run this code:

<?
if (!class_exists('gtk'))
...


The problem is function 'result'.

In this function the global declarations of '$ent1', '$ent2', '$ent2' are
not present.

This is the correct version:

function result($button, $window)
{
global $ent1;
global $ent2;
global $ent3;
$gettext1 = $ent1->get_text();
$gettext2 = $ent2->get_text();
$result = $gettext1 + $gettext2;
$ent3->set_text($result);
}

-------------------------
Roberto
http://rsoftware.altervista.org

Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.