note 44644 deleted from language.references.return by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 11 Aug 2004 23:19:14 +0000 |
| Subject: | note 44644 deleted from language.references.return by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74508@lists.php.net to get a copy of this message | ||
Note Submitter: billewicz@o2.pl
----
I have found references quite dificult to understand. I tested them for a while and finaly
understood (hopefully ;-).
So, look at this example:
<?
function &fun()
{
static $a = 5;
return $a;
}
$x = &fun();
$x++;
print $x;
print(fun());
?>
This works as desired - $a and $x are the same vars.
But if you remove any of the &'s the result will be different. I.e (upper reference
romoved):
<?
function fun()
{
static $a = 5;
return $a;
}
$x = &fun();
$x++;
print $x;
print(fun());
?>
In one moment (during returning in above code), the copy, instead of reference, will be used and, at
the end, $a and $x will be different vars.
I hope it wll help someone. Good luck.