note 37961 added to language.references.return
| From: | zayfod at yahoo dot com | Date: | Wed, 03 Dec 2003 14:23:03 +0000 |
| Subject: | note 37961 added to language.references.return | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61329@lists.php.net to get a copy of this message | ||
There is a small exception to the note on this page of the documentation. You do not have to use
& to indicate that reference binding should be done when you assign to a value passed by
reference the result of a function which returns by reference.
Consider the following two exaples:
<?php
function & func_b ()
{
$some_var = 2;
return $some_var;
}
function func_a (& $param)
{
# $param is 1 here
$param = & func_b();
# $param is 2 here
}
$var = 1;
func_a($var);
# $var is still 1 here!!!
?>
The second example works as intended:
<?php
function & func_b ()
{
$some_var = 2;
return $some_var;
}
function func_a (& $param)
{
# $param is 1 here
$param = func_b();
# $param is 2 here
}
$var = 1;
func_a($var);
# $var is 2 here as intended
?>
(Experienced with PHP 4.3.0)
----
Manual Page -- http://www.php.net/manual/en/language.references.return.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37961
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37961&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37961&report=yes
Search -- http://master.php.net/manage/user-notes.php