note 47222 deleted from language.references by aidan
| From: | aidan@php.net | Date: | Sun, 07 Nov 2004 11:48:44 +0000 |
| Subject: | note 47222 deleted from language.references by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80217@lists.php.net to get a copy of this message | ||
Note Submitter: dev at kiwicore dot org
----
I've always had a really hard time deciphering the examples on this page, so if some of this is
redudant, please forgive me.
I had a case in which I had functions (not object methods), accessing an object, in the global
scope, and another object creating that object, and using it as a member variable. This is what I
thought should work:
<?php
class Bar{
function Bar(){
$GLOBALS['bar'] =& $this;
}
}
class Foo {
function foo(){
$this->bar = new Bar;
}
}
$foo = new Foo;
?>
However, $GLOBALS['bar'] and $foo->bar are NOT the same object! In class foo, what you
actually want to write is:
<?php
$this->bar =& new Bar;
?>
I thought I understood references pretty well, but I was a little surprised when that worked as
intended, I suspect I misunderstand exactly how and when the constructor returns the object in the
zend1 engine.
----
Reason: useless note