[nycphp-talk] OO PHP-Gtk
Dan Cech
dcech at phpwerx.net
Thu Apr 15 11:20:06 EDT 2004
Scott Mattocks wrote:
>
>> function connect ($event, $callback) {
>> $callback[0]->{$callback[1]}();
>> }
>
> Is this how php-gtk handles callbacks? I was under the impression that
> it was done statically. So that with your example it would look more like:
>
> function connect ($event, $callback) {
> $callback[0]::{$callback[1]}();
> }
>
> I think it has to be calling the methods statically because if I have
> two methods, one that sets the member var and the other that checks the
> value and reacts, I get very confusing results.
>
> ...
> var $memberVar = FALSE;
> ...
> $button->connect('event', array($this, 'method1'));
> $button->connect_after('event', array($this, 'method2'));
> ...
> function method1() {
> echo $this->memberVar;
> $this->memberVar = TRUE;
> echo $this->memberVar;
> }
> funciton method2() {
> if ($this->memberVar) {
> echo 'It worked';
> } else {
> echo 'It didn't work';
> }
> ...
>
> Method one will print exactly what you would expect, but when I get to
> method2, memberVar is FALSE again and I get 'It didn't work.'
My guess would be that you need to set the callback functions like:
$button->connect('event', array(&$this, 'method1'));
$button->connect_after('event', array(&$this, 'method2'));
With the ampersand they *should* be called correctly, whereas without
the ampersand each will work on it's own *copy* of $this.
Hope this helps,
Dan
> Thanks,
> Scott Mattocks
More information about the talk
mailing list