Re: [PHP4BETA] return references branch merged into the main repository
| From: | Zeev Suraski | Date: | Wed, 15 Dec 1999 22:26:39 +0000 |
| Subject: | Re: [PHP4BETA] return references branch merged into the main repository | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-7981@lists.php.net to get a copy of this message | ||
At 00:17 16/12/1999 , Andrei Zmievski wrote:
On Thu, 16 Dec 1999, Zeev Suraski wrote: If you use no special notation, foo() is a standalone expression, not different from $var. When you assign this expression to another variable, if you assign it using the standard assignment notation, it'll create a copy of whatever that expression was (foo() could have returned a reference, and $var could have been a reference, but when you assign them to some variable, that variable, no matter what, will not be a reference to them but a copy of them). To assign a reference, you must use the special assign-reference notation. When assigning a variable, the notation does the job of converting the variable to a reference if necessary. When assigning a function return value, you must first have a function that returns a reference (because we don't want users to take references from functions that aren't designed for that), and then still, say that you want to actually take a reference from that reference, and not create a copy of it. It's just a matter of consistency. Ok, I'm just saying it's going to be real easy to forget that & if you know function returns a reference.I don't really agree. In the (very unique) cases when you would actually need to take a reference from a return value, you would probably remember to do it, and actually, it's preferred that you would do that intentionally. References in PHP are perhaps the second *real* type there is, in addition to standard variables. Conversion between references and normal variables is not transparent (intentionally), and there are strict rules of interaction between these two types. Because standard auto-converstion logic doesn't really work with references<->normal variables, the differentiation has to be dealt in a way that is similar to strongly-typed languages, such as C. In C, the function declaration has to declare the type of its return value (which is the responsibility of the function author). The function user, in turn, has to expect that type, and assign it to a variable of the appropriate type (or use it in an appropriate context). Since there are still no strict types in PHP (and there never will be, most probably), using an operator notation is the only option. And now, some sleep. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/