Connecting data

From: Date: Fri, 03 Dec 2004 12:37:22 +0000
Subject: Connecting data
References: 1 2 3 4 5 6  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-5295@lists.php.net to get a copy of this message
Well... lets say have the following: class Thing{ var $stuff; function Thing(){ $button = &new GtkButton(); $this->stuff = 0; $button->connect("button-press-event", array($this, "Increment")); $this->stuff = 10; } function Increment(){ $this->stuff++; echo $this->stuff; } } When the button is clicked I won't get 11, 12, 13.. etc. I'll get 1, 2, 3 etc.. because it is taking the value of stuff when I assigned the callback, NOT when the event is called. Obviously this is a simple example. The only way I have found to get around this is to pass the callback the value as a reference (and declare it as such in the callback function as well). This seems rather... silly and defeats the point of class variables. Its also one hell of a headache. So while I have a workaround atm.. its rather a kludge. -- Greg. ----- Original Message ----- From: "Steph" <steph@zend.com> To: "Gregory Wild-Smith" <greg@twilightuniverse.com>; <php-gtk-general@lists.php.net> Sent: Friday, December 03, 2004 12:10 PM Subject: Re: [PHP-GTK] Connecting data
Hi Gregory, Humour us with better clues :) Do you have a code snippet that will explain what you mean? (Please not the whole app..) - Steph ----- Original Message ----- From: "Gregory Wild-Smith" <greg@twilightuniverse.com> To: <php-gtk-general@lists.php.net> Sent: Friday, December 03, 2004 1:32 PM Subject: [PHP-GTK] Connecting data
Humour me here.. maybe I'm doing something VERY wrong, but the behavior
here
seems extremely wierd. When I connect an a function to an event it pulls all the data out at the time I connect it, NOT when the event happens. This means its pretty much impossible to have dynamic actions based on events. Its totally insane. Is there any way to stop this rather crazy and counter-intuative behavior? All I want to do is get the data when the function is actually being
used..
it doesn't sound too hard but it seems imposible atm. - Greg. -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.gtk.general (#5295) next »