note 14078 deleted from language.references.return by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:25:40 +0000 |
| Subject: | note 14078 deleted from language.references.return by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57350@lists.php.net to get a copy of this message | ||
Note Submitter: scott@swiftview.com
----
As someone mentioned above, references can be used to combat the syntax:
$z = do_something_to($z);
If do_something_to() takes its argument by reference, you can simply say:
do_something_to($z);
However, this also can be error-prone since users of the function might not realize that the
parameter is passed by reference, and they might be surprised when $z changes as a result of the
function call.
IMHO, the best solution is to use objects, and a method syntax:
$z->doSomethingTo();
This makes it explicit that $z itself is being manipulated (not a copy of $z). If you find yourself
always getting confused by references in PHP, perhaps you should consider a more object-oriented
approach to what you are doing.