returning a reference from a function ?
| From: | Hartmut Holzgraefe | Date: | Mon, 25 Oct 1999 13:07:08 +0000 |
| Subject: | returning a reference from a function ? | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-5686@lists.php.net to get a copy of this message | ||
Is there any legal way to return something from a function
by _reference_ instead of _by copy_ ?
"retrun &$var;" and "$var = &function();" cause syntax errors
function byref(&$ref) { $ref = &$value; }
does not behave as i would have expected in the first place
( see also http://bugs.php.net/bugs.php3?id=2589
)
Hiding the reference ny returning it inside an object seems to work
(see code below) but i do not like the rise of the obfuscation level
-----------8<----------------------------------
$top = "original top";
class ref
{
var $ref;
};
function test1()
{
global $top;
$p = new ref();
$p->ref = &$top;
return $p;
}
$r = test1();
$x = &$r->ref;
# now assigning to $x changes $top