Re: method chaining
| From: | Ernest E Vogelsinger | Date: | Mon, 11 Nov 2002 17:02:47 +0000 |
| Subject: | Re: method chaining | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123832@lists.php.net to get a copy of this message | ||
At 17:57 11.11.2002, Terry McBride spoke out and said:
--------------------[snip]--------------------
>$tmp =& $foo->get("bar"); // note the &
>$tmp->alterBarSomeWay(); // $tmp->getBaz();
>
>No way to do that in one line. I think the reference conventions are odd.
>I can pass a variable to a function not knowing it may be referenced and
>altered (unless I check the signature), but I have to know that what I'm
>receiving from a function is a reference in order to grab it properly!?
--------------------[snip]--------------------
Note that both parties need to know the reference...
assuming
function foo::get($id) {return $something;}
it will not help (as to my knowledge) when you say
$tmp =& $foo->get('baz');
The function must be coded as
function &foo::get($id) {return $something;}
to return a reference. AND you have to accept the reference, or you'd get a
copy.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/