|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[1999-11-18 13:54 UTC] duncan at emarketeers dot com
It is not possible to return a reference from a function, the parser reports
return &$x;
as a syntax error, and using something like
$a=&$x;
return $a;
does not return a reference.
Running 4.0b3 on Apache 1.3.9, compiled with mysql
<?
class tata {
var $a;
}
class toto {
var $a;
function toto() {
$this->a=new tata;
$this->a->a=1;
}
function titi() {
$b=&$this->a;
return $b;
}
}
$x=new toto();
$y=&$x->a;
$z=$x->titi();
$y->a=5;
$z->a=6;
echo "Actual: z->a = $z->a y->a = $y->a x->a->a = ".$x->a->a ."<BR>";
echo "Expected:z->a = 6 y->a = 6 x->a->a = 6 <BR>";
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jun 17 15:00:02 2026 UTC |
it has been implemented in 12/1999, this was the original commit message: ndi and I finished working on the return references support in Zend. We tested it a bit, and merged it into the main branch. To return a reference from a function, you must tag the function as a function that returns a reference: function &foo($a, $b, $c) { ... } However, $a = foo(...) will still not cause $a to be a reference to the returned value (much like $a = $b, when $b is a reference, copies the value of $b onto $a, and doesn't make $a to be a reference to $b). In order to make $a be a reference to the returned value, you must use the notation: $a = &foo();