Re: [PHP4BETA] return references branch merged into the main repository
| From: | Andrei Zmievski | Date: | Wed, 15 Dec 1999 22:07:57 +0000 |
| Subject: | Re: [PHP4BETA] return references branch merged into the main repository | ||
| References: | 1 2 3 4 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7978@lists.php.net to get a copy of this message | ||
On Thu, 16 Dec 1999, Zeev Suraski wrote:
> It's partially double work, true, but if you think about it, there's no
> real other consistent way to do it.
> First, you don't want to let users take references from functions that
> don't intend to return references; That's a basic encapsulation rule. So,
> you must note that you're returning a reference in the function
> declaration, as the function author.
Right, & in function declaration should stay there.
> Second, an expression that is a reference, when assigned to a variable,
> does not create another reference, but a copy of its value:
> $a = &$foo; /* $a is a reference to $foo */
> $b = $a; /* $b is NOT a reference to $foo, it just contains $foo's
> original value */
> $c = &$a; /* $c IS a reference to $foo */
> For that reason, if you do
> $a = foo()
> even if foo() evaluates to a reference, $a = ref_expr causes $a to be a
> copy of the value of ref_expr, not a reference to it.
So what you're saying is there is no way to tell whether foo() returns
reference when it's being executed?
-Andrei
Nobody tried to design Windows - it just grew in random
directions without any kind of thought behind it.