Re: is this a bug or expected ??

From: Date: Thu, 19 Jul 2001 16:01:24 +0000
Subject: Re: is this a bug or expected ??
References: 1  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-2285@lists.php.net to get a copy of this message
This is once again the manifestation of the difference between passing by value and by reference. You specify your method callback as array($this, 'showw') which means that your $this instance will be passed by value and that in that instance $test_var is still empty. If you specify array(&$this, 'showw') your instance will be passed by reference and the $test_var value will be reflected accurately. On Thu, 19 Jul 2001, Rich Payne wrote: > > Can someone tell me if this is "normal" for php or not...my feelings would > be that there's something wrong here...anyway. I have a class: > > <?php > > dl('php_gtk.so'); > > Class password_dialog extends GtkWindow { > var $test_var; > function password_dialog() { > $this->GtkWindow(); > $this->set_title("Test Window"); > $bt = &new GtkButton("TEST"); > $this->add($bt); > > $bt->connect('clicked',array($this,showw)); > > $value="Test String \n"; > $this->sett($value); > > //$bt->connect('clicked',array($this,showw)); > $this->show_all(); > > } > function showw () { > echo "var is ".$this->test_var." \n"; > } > > function sett ($val) { > $this->test_var = $val; > } > > } > > we have a class variable ($test_var), now if I run the class the way it > is, then clicking the button produces: > > var is > > if I move the position of the event connection for the button (comment out > the first, uncomment the second) then it works. So where I register for > events is going to effect the value of class variables? > > here's the script that will run this class: > #!/usr/bin/php > <?php > > include ('password_dialog.php'); > > $test = &new password_dialog(); > > /* Run the main loop. */ > Gtk::main(); > ?> > > > needless to say my head is spinning on this one..... > > thanks, > --rdp > > -- > Rich Payne > rpayne@alphalinux.org www.alphalinux.org > > > -- > PHP GTK Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-gtk-unsubscribe@lists.php.net > For additional commands, e-mail: php-gtk-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -Andrei * Life may be expensive, but it includes an annual free trip around the sun. *

« previous php.gtk (#2285) next »