On Mon, Dec 22, 2003 at 11:57:58AM +0100, rush wrote:
> Hello,
>
> I have a problem understanding following chunk of code. It seems that global
> $rme does not remember an reference to $this, but instead it is remembering
> null or something like that:
>
> <?PHP
>
> class A {
> function rememberMe() {
> global $rme;
this creates a reference from $rme to $GLOBALS['rme']
> $rme = & $this;
this create a *new* reference from $rme to $this. so only a local $rme
is referencing $this now. change the line to
$GLOBALS['rme'] = & $this;
to get the expected behaviour.
> $this->someInstanceVar =77;
> }
>
> function report() {
> global $rme;
> echo 'X'; print_r($rme); echo 'X';
> }
> }
>
> $a = new A();
> $a->rememberMe();
> $a->report();
>
> ?>
>
> This little script outputs:
> XX
>
> While I would expect it to return:
>
> Xa Object ( [someInstanceVar] => 77 ) X
>
> rush
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php