Re: [PHP4BETA] problem: references
[email protected] (Stanislav Malyshev) Wed, 31 May 2000 16:46:43 +0300 (IDT)
| Newsgroups | php.version4 |
|---|---|
| Organization | Zend Technologies Ltd (http://www.zend.com/) |
| Message-ID | <[email protected]> |
DM>> <?
DM>> class test {
DM>> var $x;
DM>> function getx (&$r) {
DM>> $r = &$this->x;
DM>> }
DM>> }
DM>>
DM>> $v = "some text";
DM>> $t = new test;
DM>> $t->x = 10;
DM>> $t->getx ($v);
DM>> print ("test=$v");
DM>> ?>
DM>>
DM>> and result is ... "some text" !!!
Well, seems that you cannot do that. You cannot assign references via
references, I think - that's just doesn't work this way in PHP. When you
assign another reference, you are re-binding old reference, breaking old
link and creating new - but not changing contents of the first link. I
know this is a bit strange, but that's how it presently works.
DM>> what i want is to get the _reference_ to the $t->$x but via
DM>> function.(btw. can function return a reference?)
Yes, it can. IIRC, you should say "function &foo() { ....; return
$bar; }".
--
Stanislav Malyshev [email protected]
+972-3-6139665