Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32740 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97424 invoked by uid 1010); 12 Oct 2007 20:27:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 97409 invoked from network); 12 Oct 2007 20:27:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Oct 2007 20:27:33 -0000 X-Host-Fingerprint: 84.166.5.249 p54A605F9.dip0.t-ipconnect.de Received: from [84.166.5.249] ([84.166.5.249:16390] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/76-55112-4B8DF074 for ; Fri, 12 Oct 2007 16:27:33 -0400 Message-ID: To: internals@lists.php.net Reply-To: "Sebastian" References: <2C.E0.51252.D52DB074@pb1.pair.com> Date: Fri, 12 Oct 2007 22:28:02 +0200 Lines: 61 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-Posted-By: 84.166.5.249 Subject: Re: new feature -> with() From: sebastian@ifyouwantblood.de ("Sebastian") hi, wow, thats what you're writing is a chain call. this only works, if the methods of a class return the object $this. but if you need a return value other than $this, simply there is no real way. and moreover i don't agree with the other arguments. what i'm suggesting is, that in with(){} you are only allowed to use the methods and variables defined in the object you are using with(). as in the sample, you are not using any global functions or else. my opinion is, this it is especially with $this very useful. greetings ----- Original Message ----- From: "Ralph Schindler" To: "Sebastian" Cc: Sent: Wednesday, October 10, 2007 6:08 PM Subject: Re: [PHP-DEV] new feature -> with() > >> --------------------------- >> $class=new class; >> >> with($class) >> { >> do_something(); >> do_more(); >> do(); >> } > > What more value does this hold over implementing fluent interfaces which > are already possible? > > Assuming > class Foo { > public function doSomething() { /**code**/ return $this; } > public function doMore() { /**code**/ return $this; } > public function doDo() { /**code**/ return $this; } > } > > You can do this: > > $bar = new Foo() > $bar->doSomething()->doMore()->doDo(); > > or, if you want exceptional fallthrough: > > try { > $bar->doSomething() > ->doMore() > ->doDo(); > } catch (Exception $e) { > ... > } > > -ralph