note 47222 added to language.references
| From: | dev at kiwicore dot org | Date: | Sun, 07 Nov 2004 05:05:37 +0000 |
| Subject: | note 47222 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80208@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47222
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47222&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47222&report=yes
Search -- http://master.php.net/manage/user-notes.php