Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94468 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71457 invoked from network); 11 Jul 2016 15:34:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2016 15:34:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:38433] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/49-22463-57CB3875 for ; Mon, 11 Jul 2016 11:34:14 -0400 Received: by mail-wm0-f41.google.com with SMTP id o80so56528901wme.1 for ; Mon, 11 Jul 2016 08:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5cOpUhr13k1HbA8d9hfYayW/VId9MlW859mziNvk8oE=; b=JTADPlV/1X5X7/3fnTV16/Oc2IfywTho3ph2rudK56uOG+VGSfx1febptWbouA6A6k SOhdtpOq89BL2rxwzYa2woBq0ssCE0N6mzUUnj6hxlzMeuE3ntQVhOCU0GGfU1GvNuKv fkLnISmh0a4ffsDTtbcPItqZ5MHFuacrjnLNdfB3FGcOKhP7HjG9tqIpSmcK6JzBgybg wsj4thYbX4aSB+WA9jJobIN8ILijdclYZHGs42+C2E19+B5Qcj2XfZFNLuq7eoFRTTiW nHaXiQeiVp11cy8pNRUe5VD1shgGsGqfWRC7kJJJo848akg8ey4tYn/8N2iGDcERk5hF uMtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5cOpUhr13k1HbA8d9hfYayW/VId9MlW859mziNvk8oE=; b=D0tqswpBsKt0CEZoKTWGPbcjKzIduviEeYanhJieNwgZEZol+ATckiXzIQDeNY2CGh Vi4QEg5h1rjbJzEr13ty7ba/ntGGhbsq12ZsqsofNhRn873F5p0ygdp7BEVxoN57eWUe kCJyzkk4Ws97ClDIZL+ZvoIQmy6hJ+SB6nA1Kdd8eq3h66n4lR1qBqI9PfnWOO3USAHZ RTr3TCxK30zqRDCpGzc2f9O32O7D0tTm78Qex3DPWsXUIrp24z8Ce6h5LlQUU1tUhSxq 6/F1ZXOb0gH0wtLmxgDIJ9h6aBFnmwcfKLy7WiIIRGRIZa1x+zj0z5iVnFSQszftDuCf jDRQ== X-Gm-Message-State: ALyK8tIRwNI38OMVgUfbSWUAS0NVpUMlMxhteRP97+3EM+X3yQQ7wbfrl/vlIVRXr+LEzFE+ZvjHQ3k2kNe2dw== X-Received: by 10.28.169.203 with SMTP id s194mr8646602wme.95.1468251251274; Mon, 11 Jul 2016 08:34:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.37.202 with HTTP; Mon, 11 Jul 2016 08:33:51 -0700 (PDT) In-Reply-To: <86455a1e-eb57-1f30-9016-ac70c9f30bdd@gmail.com> References: <86455a1e-eb57-1f30-9016-ac70c9f30bdd@gmail.com> Date: Mon, 11 Jul 2016 17:33:51 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary=001a114bab5245fa0c05375de281 Subject: Re: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return) From: ocramius@gmail.com (Marco Pivetta) --001a114bab5245fa0c05375de281 Content-Type: text/plain; charset=UTF-8 Still interested: what's the actual added value of this sort of operator? Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 11 July 2016 at 17:28, Rowan Collins wrote: > On 11/07/2016 16:15, Michael Morris wrote: > >> But for that to currently work setSomething must return $this. A cascade >> operator would avoid this. What about => ? >> >> $a->setSomething('here')=>setSomethingElse('there'); >> > > This will be ambiguous with array syntax, e.g. > > $foo = [ $a->foo() => bar() ] > > could be a call to $a->foo() for the key and to bar() for the value, or > just a chain ending with the array value $a->bar(). > > Naming things is hard. Inventing operators is harder. ;) > > Also note that it's the *first* call that needs a special operator, in > order to discard the normal return and substitute the left-hand side, > otherwise mixed chains become ambiguous and probably horrible to implement > in the engine: > > $foo->bar()->baz()=>bob() // what is $this inside bob() ? > > > > For this sort of chaining I'd propose, in addition to the cascade operator, >> the chain operator. This would work like the cascade operator except that >> the return of the function is implicitly the first parameter of the next >> argument in the chain. Something like this? >> >> $a->add(1, 2):>subtract(3):>add(4); // return 4. >> > > This exact feature was proposed a couple of months ago by Sara Golemon. > See https://wiki.php.net/rfc/pipe-operator and the accompanying > discussion http://marc.info/?t=146196088900001&r=4&w=2 > > As far as I know, it's not been formally withdrawn, so might be > resurrected in some for for 7.2. It might be interesting to see a cascade > operator at the same time, but some of the same concerns that came up in > that discussion will probably apply to any proposal. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a114bab5245fa0c05375de281--