Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118416 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76064 invoked from network); 11 Aug 2022 16:40:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2022 16:40:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 54F5418037F for ; Thu, 11 Aug 2022 11:42:53 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 11 Aug 2022 11:42:52 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 68A8F32009CE for ; Thu, 11 Aug 2022 14:42:51 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Thu, 11 Aug 2022 14:42:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm1; t=1660243370; x=1660329770; bh=PLYL1lo12dOoyHdKq1HtWMAf5 jljaZCOZA/9wtPBhsU=; b=q/INeWqs0ZukTH/1JPiUZvH/Gpotx/h0sYdsHu2OS g9Wv84ToftmT650lGK67Ny8FPYlrcqRyCDtkL1F/Deg2OOP2hl73VgGURn6mt2Wg ZY1YgMF6DXY9JLnN5IrdW3hmYhjMDZ5G5JeULKWMKfN+sSCXh73hwp8XHiPtJG18 vrISEIZ2RwgoatCNVF5Rrh69IoDmeMYInIvPHj8dpZaXRkLfAnqGDKIH49XGErM/ nMkNYp+MNyFIK7+oRUbGbR+sK6CaZYM/V8M/T83hmUHuol+4nTgjbfXlZZ72yO+y 4sZy1ZtNiFGGD+svWgOhvKV9yPB2BPXxKMgXA0D/+Ui8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1660243370; x=1660329770; bh=P LYL1lo12dOoyHdKq1HtWMAf5jljaZCOZA/9wtPBhsU=; b=xLy9nBYMGsM0ibMj5 WXBqybXJ/l6si/SqyhN/hWt/wo/waqFnwyfb2O8lEuIWlz+X1ASdA1efv7u2mgL1 qVgf8A9lySrGEA3pUjET6debjJ3iDmboG9KK9uuInNNkRTDzJcSd3tBh3m6RDgIf vfIfN0gpIH4NiUYz+BF2RmBFlPyrxbq7+DOkEVW4fFlg7qZaylIvZrMHS7MCoIjP FusclC6TkdBul0P6wg+jZ/gWe4GELbRCx9qt0jBuSNjfVjGbOqKKEjsHLnSNQEHo wz1Sg84q0l00ota3/w17Vae0izk/1hi/3aZZ+GHEtqSwsAZxe2RB6+dWZqufVXLw 0TxSw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdeggedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpefhkedtfffghfekieduhedvheefgfefheeugfdv leetteektefgteejieeltdelkeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhies ghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id BD3A91700082; Thu, 11 Aug 2022 14:42:50 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-811-gb808317eab-fm-20220801.001-gb808317e Mime-Version: 1.0 Message-ID: In-Reply-To: <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> References: <62f48769.250a0220.37387.53b5SMTPIN_ADDED_MISSING@mx.google.com> <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> Date: Thu, 11 Aug 2022 13:42:30 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Concept] Extension methods From: larry@garfieldtech.com ("Larry Garfield") On Thu, Aug 11, 2022, at 4:03 AM, Alex Wells wrote: > Besides, I believe working with existing functions is more of a proble= m=20 > than a bonus - because of the naming. You=E2=80=99d have to clutter yo= ur code=20 > with `array_map` calls, even though it could easily be shortened to=20 > `map`. A couple of trivial higher order functions and you're good to go. I hav= e a sampling of them here: https://github.com/Crell/fp/blob/master/src/a= rray.php (Modulo PHP's inconsistency between internal/user-space functions that f= orce having separate functions for keyed and unkeyed arrays; any solutio= n is going to have to deal with that problem.) >> On 11 Aug 2022, at 07:36, Paul Crovella wro= te: >>=20 >> This is essentially making `->` the pipe operator with extra steps (`= extension`/`use extension`) and less utility (not working on existing fu= nctions.) > > Well, pipe operator is another option, but it=E2=80=99s got it=E2=80=99= s downsides=20 > compared to extension methods: > - it's less versatile: extension methods are required to specify a=20 > type they=E2=80=99re extending, meaning they are methods, not function= s. Hence,=20 > two different `map` method extensions can be imported in a single file=20 > (given they=E2=80=99re for different types - say one for `Collection`,= the=20 > other for `array`), unlike regular functions. I believe it=E2=80=99s c= ommon=20 > place to use both `Collection::map` and `array::map` in a single file,=20 > but that wouldn=E2=80=99t be possible or would require aliasing > - it=E2=80=99s uglier: since it just uses functions, to avoid clashes= between=20 > same method names, prefixes would be required Flipside: Pipe works on arrays and strings, which this would not. And a= rrays and strings are among the most common things to be chained in this= way. (Most Collection objects are just alternate OOPy syntax around ar= ray_map and array_filter, at the end of the day.) Pipe also doesn't giv= e the impression that the method is "part of" the object (it's not), whe= reas extensions do, despite being effectively just an alternate syntax f= or a public function that takes the object as an argument. And functions can be easily namespaced. --Larry Garfield