Re: Connecting data

From: Date: Mon, 06 Dec 2004 13:38:46 +0000
Subject: Re: Connecting data
References: 1 2 3 4 5 6 7 8 9  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-5311@lists.php.net to get a copy of this message
Gregory Wild-Smith wrote:
I didn't realise the callback was passed as a copy, that does make the behavior make more sense. However I've never encountered this behavior in PHP before. Perhaps that's just me. It is however very anoying ;) Why will php-gtk2 not do this?
The callback isn't passed as a copy. The copy is made when you put $this into the array. The array that you passing to the callback is being passed by reference because of the connect() function signature. When you call connect() with an array you are doing a couple of operations at once. The part that most people miss is the creation of the array (array(&$this, 'method')) If you look at that part alone it is a little easier to see what is going on. In PHP4 everthing is passed as a copy unless you tell it specifically not to. You need to specifically tell the array to use a reference rather than a copy of the $this object. PHP-Gtk2 will use PHP5. In PHP5, objects are always passed by reference. This means that array($this) and array(&$this) will both pass the $this object to the array as a reference instead of making a copy. It is more along the lines of what you would expect from a traditional OOP perspective. I hope that makes sense. I am not the best at explaining these things. -- Scott Mattocks scott@crisscott.com http://www.crisscott.com http://pear.php.net/user/scottmattocks

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