Re: [PHP4BETA] problem: references
| From: | Stanislav Malyshev | Date: | Wed, 31 May 2000 13:46:43 +0000 |
| Subject: | Re: [PHP4BETA] problem: references | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-15976@lists.php.net to get a copy of this message | ||
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 stas@zend.com
+972-3-6139665