note 44203 added to language.references
| From: | jlaing at gmail dot com | Date: | Sun, 18 Jul 2004 00:28:52 +0000 |
| Subject: | note 44203 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73464@lists.php.net to get a copy of this message | ||
While trying to do object references with the special $this variable I found that this will not
work:
class foo {
function bar() {
...
$this =& $some_other_foo_obj;
}
}
If you want to emulate this functionality you must iterate through the vars of the class and assign
references like this:
$vars = get_class_vars('foo');
foreach (array_keys($vars) as $field) {
$this->$field =& $some_other_foo_obj->$field;
}
Now if you modify values within $this they will be modified within $some_other_foo_obj and vice
versa.
Hope that helps some people!
p.s.
developer at sirspot dot com's note about object references doesn't seem correct to me.
$temp =& $object;
$object =& $temp->getNext();
Does the same exact thing as:
$object =& $object->getNext();
when you refernce $temp to $object all it does is make $temp an alias to the same memory as $object,
so doing $temp->getNext(); and $object->getNext(); are calling the same function on the same
object. Try it out if you don't believe me.
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44203
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44203&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44203&report=yes
Search -- http://master.php.net/manage/user-notes.php