note 34306 deleted from language.references.whatdo by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:22:32 +0000 |
| Subject: | note 34306 deleted from language.references.whatdo by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57330@lists.php.net to get a copy of this message | ||
Note Submitter: agatesystems@yahoo.com
----
Re: ampersands in function definitions
There is a prior comment that "in practice you won't need ampersands in function
definitions." This is not really true; ampersands in function definitions *do* change the way
PHP behaves.
I have an application that has an array of "references to objects". A function that wants
to return a reference to an object requires the "function &foo()" notation. If the
ampersand is missing, a copy of the object is made, regardless if the invocation is "$obj =
foo()" or "$obj =& foo()".
For many applications, the difference between "function &foo()" and "function
foo()" won't be apparent, simply because return by value is the correct behavior.