Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100007 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48034 invoked from network); 22 Jul 2017 11:37:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jul 2017 11:37:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=aidantwoods@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=aidantwoods@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: aidantwoods@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:36891] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/2D-02884-2E833795 for ; Sat, 22 Jul 2017 07:37:08 -0400 Received: by mail-wm0-f51.google.com with SMTP id v139so3726202wmv.0 for ; Sat, 22 Jul 2017 04:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=OcsKT0xQV61U55LdmKu/F23HJhRG1o5U7dXC8E3QRSg=; b=dRpxswpxISOJtM+LkFR3wycHjXY7v1O/xT2psdDBEFIYa+NYQxw6dJBKn74KxGTV6p l3sTNLmQC3QG20+9YNHpvcDkuV9d5y88/gS9kDL2Lalx//xrlIDLYoiCd9pAK6+XCf8B LLm6/cmTxmul3BqyezeHWg8mBb7o4wr0JbhiVoI/5AisTCnY9oJ6c7OZIRfCdrri37Ko 4sd7WVZiuzjdiRTXnnMRXYlMy9LZsY4zaMd1drWphM3LkPhFANUJPUtMShJBXmIEiMoZ +oi9Cm06VyYQz+4YL2j9LHp0rkAD2qCd5PGLF8Q8QAP/jlW19/2gS1R1zfTXKy14v4FI UmDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=OcsKT0xQV61U55LdmKu/F23HJhRG1o5U7dXC8E3QRSg=; b=sUw8ijYZihHSyQyA0US/U0yulU6zlvCTWmoRr7gDBNjOzwa6vbvyENRFDICmMoe1ug 7A29PQhrH9Zabyq1XzT6B5M4oWIf3k52ulanVXdNJexRPQUMUOyKpGTqdeTKj30TPKbz XIS38Gr73SvRMyIpQ3yIfHxy36wx6b/wAnbMR+KBMS/bce7/+/GYFKCaQ8/13hhJuQzw mSln3Z8PJ5vkGE9xxzrTdECbSQC6QL4pPej6IATgpCdxN4ucZ/KL4ft5Rvgek+7ORGP0 kOe+sIfie2InjsGeYUN32iRvyuXJL+pFUXdqmeR2qnhsH9nHMr459M9aLoE0sC6TANZR NSNA== X-Gm-Message-State: AIVw113H7MrkUdZcRPJuxP/StGxngf5thu/qCJAT/Gv9nk2zideJpoPJ 8Kj6rrR49gKaDtOBMm2rn3Y0S+pOOfqHitM= X-Received: by 10.28.230.199 with SMTP id e68mr1339442wmi.138.1500723424059; Sat, 22 Jul 2017 04:37:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.181.136 with HTTP; Sat, 22 Jul 2017 04:37:03 -0700 (PDT) Date: Sat, 22 Jul 2017 12:37:03 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="001a11476f9c98ecad0554e66630" Subject: Pass-through object operator From: aidantwoods@gmail.com (Aidan Woods) --001a11476f9c98ecad0554e66630 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Internals! I'd like to gauge a reaction on a potential RFC proposal. As per the RFC howto, I shall state that this would be a "concept" as I don't have anyone lined up that would implement the feature, and I'm not a C dev myself. (Though if no one volunteers I may take this as a learning opportunity ;-) ). The proposed feature is regarding method chaining. There appear to be two design patterns that use it: 1. Where you deliberately act on very different objects returned in a "flow" like way, e.g. ``` $boo =3D $App->getConfig()->getId('foobar')->getValue(); ``` 2. For configuration, saving typing the original object multiple times ``` $FooBar ->loadConfig($Config) ->loadExtensions($Extensions) ->run() ; ``` For the former, it relies on you knowing what is returned, and makes a nice way of using what was returned easily. For the latter, the actual method itself returning the instance seems a bit useless as actual information (unless dealing with immutable objects =E2=80= =93 where it in-fact returns a *new* instance. But that's really just the former case =E2=80=93 since the method was designed with returning somethin= g in mind anyway). So I wonder whether for the latter case, it would almost be better to implement that kind of method chaining as a language feature (instead of (ab)using a return statement that doesn't have anything to do with the method's role). So I would propose a new operator, perhaps `&>` is decent notation =E2=80= =93 but that could be discussed further if we like the concept. Assuming it's `&>` in the following though: `&>` would work almost exactly like `->`, except that instead of evaluating to the value returned by the method call, it would evaluate to the object on the LHS. A kind of "pass-through" operator if you will. So instead of the author of the object adding support for this configuration method chaining style (they might not be able to for all methods), you could instead use the `&>` operator to do it =E2=80=93 this a= ll in a way that is clear to the reader too. You could even use it on methods that *do* return things (if you don't care about what's returned). I.e. write this (knowing that it would work: because language feature). ``` $Foo &>bar() &>baz() ; ``` Which would have the written meaning: "call `$Foo`'s `bar()` *and* `baz()` methods". Other examples: You want to instantiate an object *and* call a couple of methods, and also get a reference to that object. Before: ``` ($Foo =3D new Foo)->bar(); $Foo->baz(); ``` With the "pass-through" operator: ``` $Foo =3D (new Foo)&>bar()&>baz(); ``` Thanks for reading if you got this far, I shall look forward to hearing feedback. Kind regards, Aidan --001a11476f9c98ecad0554e66630--