Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118421 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83596 invoked from network); 11 Aug 2022 17:00:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2022 17:00:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D34911804F8 for ; Thu, 11 Aug 2022 12:02:48 -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)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 11 Aug 2022 12:02:48 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 87843320091B for ; Thu, 11 Aug 2022 15:02:47 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Thu, 11 Aug 2022 15:02:47 -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=1660244567; x=1660330967; bh=IciQHqOdNoKh61nFoP/4pDPqd wm49roRfRO2mxpl3h0=; b=mKuz0t81kG792sZUSWklKTtNvZBXlQMnqEKp1tLmg rC1bnRMT3YQ6Cc4xNdKU0tUxu/K4QbafhxPct+JFDmY9ncz8TqhSPy/930okK6AB qumxJs1/yfbXkuSW5NCJAqBwh/JTyQxJNy2aILZ9R7e7K9OKeaRj9B5fWazWNKEk 5+8obYpZRZvc+O0VXm2EkXd+SneC6JusGt4oNnxM+IccUg45tmVWKjmXKEbTlHFB LqcJof/GR0pDtlfYY+kn9Um/bKLCeUI89/eXNOAxsAPi2sJvobTo1Z7WRAuwYKGq XQFwppcmD3NpGnckVs2nPphnrubuonfsk8X4lHBfrgbfg== 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=1660244567; x=1660330967; bh=I ciQHqOdNoKh61nFoP/4pDPqdwm49roRfRO2mxpl3h0=; b=0bYCjs3YeoiPY8qwI APHenbVFEwIZJ8FU9tCLl0TKzmJQNUAve7h921CEUIdwH2I2y9jKBwtmXtNWjbDs Bzw8vrJVXjaxuV+EkYcN3dj5kAL5/61g3zGPGRhKNrqCibSLMi56i8gUVxh0jPyw AooQwyFN5/JByLa5G2RVhCvJ5EjuNVBF5btAglHVVnD+2/yR9EyJAWNBtuRCPjgk UnkeG/FzkWfg4lqG0AmTzobGsEjHXrupJha3VwZcEzXhhSctJdIH0IwErh5anCLc c0CGXU0HeL2y03LFfnCaSZnuV0OHkteAQE1xxsZriZUbE18IZerEH5psbI3V43zQ IceeQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdeggedgudeffecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeeggeehgfetjeehgefggefhleeugefgtdejieev vdethfevgeeuudefleehvdetieenucffohhmrghinhepphhhphdrnhgvthenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id C4BC71700082; Thu, 11 Aug 2022 15:02:46 -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: <5B9CECB4-2B42-4DA2-870F-A44508C0F9E3@gmail.com> References: <62f48769.250a0220.37387.53b5SMTPIN_ADDED_MISSING@mx.google.com> <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> <5B9CECB4-2B42-4DA2-870F-A44508C0F9E3@gmail.com> Date: Thu, 11 Aug 2022 14:02:26 -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 1:59 PM, Alex Wells wrote: >>> Well, pipe operator is another option, but it=E2=80=99s got it=E2=80= =99s 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 functi= ons. Hence,=20 >>> two different `map` method extensions can be imported in a single fi= le=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= common=20 >>> place to use both `Collection::map` and `array::map` in a single fil= e,=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 clashe= s between=20 >>> same method names, prefixes would be required >>=20 >> Flipside: Pipe works on arrays and strings, which this would not. An= d arrays and strings are among the most common things to be chained in t= his way. (Most Collection objects are just alternate OOPy syntax around= array_map and array_filter, at the end of the day.) Pipe also doesn't = give the impression that the method is "part of" the object (it's not), = whereas extensions do, despite being effectively just an alternate synta= x for a public function that takes the object as an argument. >>=20 >> And functions can be easily namespaced. >>=20 >> --Larry Garfield >>=20 >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: https://www.php.net/unsub.php >>=20 > > Why would this not work on arrays and strings? The intention is the=20 > exact opposite: allow extension on (almost) all types allowed in PHP.=20 > That includes all scalars, object, iterable, array, mixed, all classes= ,=20 > interfaces & enums.=20 How feasible is that to implement? > Regarding the impression, I agree. I=E2=80=99m not sure if this is a p= roblem=20 > though, as this isn=E2=80=99t a problem in other languages. I=E2=80=99= m aware it=E2=80=99s not=20 > a correct to compare PHP with other languages, but in this context PHP=20 > is facing a question that wasn=E2=80=99t much different for other lang= uages.=20 > This is also easily solvable by introducing an extension member access=20 > operator - something like `->>`. Alternatively, an IDE can just=20 > highlight a method as being from an extension. Numerous languages also included a pipe operator to handle this use case= , so... =C2=AF\_(=E3=83=84)_/=C2=AF --Larry Garfield