Re: is this a bug or expected ??
| From: | Rich Payne | Date: | Thu, 19 Jul 2001 17:19:39 +0000 |
| Subject: | Re: is this a bug or expected ?? | ||
| References: | 1 | Groups: | php.gtk |
| Request: | Send a blank email to php-gtk+get-2287@lists.php.net to get a copy of this message | ||
On Thu, 19 Jul 2001, Andrei Zmievski wrote:
> 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.
OK, I follow that (and it clears a lot up) but it still doesn't quite fix
the problem.....I've changed:
$bt->connect('clicked',array($this,showw));
to be:
$bt->connect('clicked',array(&$this,showw));
So we're now passing a reference to $this to the function, but here's the
output:
[richp@nobleman temp]$ ./main.php
X-Powered-By: PHP/4.0.6
Content-type: text/html
var is Test String
var is test_varg
var is test_varg
var is test_varg
var is test_varg
It seems that accessing it once is fine, but after that something goes
wrong. The same is true even if I just do a var_dump before the echo,
somwething like:
function showw () {
var_dump($this->test_var);
echo "var is ".$this->test_var." \n";
}
the first var_dump shows I have a string with the correct contents, the
echo after that shows nothing....
[richp@nobleman temp]$ ./main.php
X-Powered-By: PHP/4.0.6
Content-type: text/html
string(11) "Test String"
var is
string(11) ""
var is test_var
string(11) ""
var is test_var
string(11) ""
var is test_var
--rdp
--
Rich Payne
rpayne@alphalinux.org www.alphalinux.org