Small riddle with classes and references, or bug?
| From: | rush | Date: | Mon, 22 Dec 2003 10:57:58 +0000 |
| Subject: | Small riddle with classes and references, or bug? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173141@lists.php.net to get a copy of this message | ||
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;
$rme = & $this;
$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
--
http://www.templatetamer.com/