Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118403 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80427 invoked from network); 10 Aug 2022 16:06:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Aug 2022 16:06:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90F70180507 for ; Wed, 10 Aug 2022 11:08:35 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f41.google.com (mail-vs1-f41.google.com [209.85.217.41]) (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 ; Wed, 10 Aug 2022 11:08:35 -0700 (PDT) Received: by mail-vs1-f41.google.com with SMTP id o123so15979074vsc.3 for ; Wed, 10 Aug 2022 11:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=goVQbsJkQwWW5rMEZAubFaEIIwAhWWdX/B7L2IEm/wY=; b=Qaz7e5crvRNp/wZRFoR/bbhczge6yAaHSWwMygGYSxeaHU6ERnkqW9P0bw30u6IcPH mOO4l9W1DB07FHcc00VTpfr9CugJRIXaxddQAcsFoeX14sl2hQQegkoWGo2gMNF68KSM x8dcu8XCH0qIu44bbq3VMdyEvIGXIxvAkOxZZaIPS/tWEeefc9wRJnwktq8nV/8BzkmB JxaUTOK9HuovDytxbR8SOpbQ7L8CdM7VAIqvshkSgfO8rXwe4sqJyPizG9yq/mxPmFsa y3aslFRj3v42WkdUEBArcLE3iEIhQYHmD6oMXmQ125nou/XrcL7ZxQiCRVfcmTXUC0pP 0j+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=goVQbsJkQwWW5rMEZAubFaEIIwAhWWdX/B7L2IEm/wY=; b=qjpspZjHYtfWGI4+CLIJVhK41dd/iMtFGVgEucRa7Kd+jCH0NdgEDSqk2LJLgHsJoq g77RVJ1aNiIHjmLoWaPM5+0OsjC8hYtmxGdy5zNNCK8VmPw0UCaZ8jG276zeRJp6u7PM 9E2xQ8TQCY26pGLN2gK0jO7o+zZc+mXqOm8fj+fEd65mK/lV7MZOdDvnHmmQNow01LHg SKk8mljimvRcQy5LnT3DjOEZ08tUIcHDLqbUySiHAyV7gGH4fKN9BV5KerjUVgjsTn/O z867Jfhx4wIWWZ6wvA2b5zPMG/JlTj5CLNVTgYosnSKwpHO2deG4LWSFzuZuOonnHZDp dK1A== X-Gm-Message-State: ACgBeo2WIIBLGlfM+JlCTOSpH39Olc9t3iTYy/FEMYx6CwIYmfo2011K 2EZ099Sm0HqIknyUmt2zuJewE1glcgEmbmWsMdw= X-Google-Smtp-Source: AA6agR53DFURpKDWL6ahvf4c+BYPG7vi98DF538pLKnuj7EEE6tlmmXRU4AJEMbVruwTHruU5qF+8MkhIFzBoEv+JoM= X-Received: by 2002:a67:c30b:0:b0:388:5975:ab with SMTP id r11-20020a67c30b000000b00388597500abmr13363248vsj.13.1660154914252; Wed, 10 Aug 2022 11:08:34 -0700 (PDT) MIME-Version: 1.0 References: <62f3da67.810a0220.ed5e8.1b2cSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Wed, 10 Aug 2022 20:08:23 +0200 Message-ID: To: Rowan Tommins Cc: Ben Ramsey , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000efae4c05e5e6efa3" Subject: Re: [PHP-DEV] Re: [Concept] Extension methods From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000efae4c05e5e6efa3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Rowan, =C5=9Br., 10 sie 2022 o 19:32 Rowan Tommins napis= a=C5=82(a): > On Wed, 10 Aug 2022 at 17:18, Ben Ramsey wrote: > > > I believe this is also called "monkey patching" in some places, and > > Ruby, Python, and JavaScript all offer some form of object extension > > similar to this. > > > > There is also the PHP runkit extension that provides some of the > > functionality you've described: https://www.php.net/runkit7 > > > > > Monkey-patching generally refers to the ability to completely "re-open" a > class, and implement additional behaviour (or even change existing > behaviour) *with the same privileges as the original definition*. > > Extension methods are a much more constrained feature - they don't break > the class's encapsulation, only provide an extra syntax for operations th= at > would already be legal. In C#, for instance, calling > "foo.someExtensionMethod(bar)" is just syntactic sugar for the static > method call "SomeClass.someExtensionMethod(foo, bar)", and cannot hide or > over-ride a real method with the same name. > > The challenge in PHP is that so little is resolved at compile-time. > Adapting the example from the first post: > > namespace App\Business; > use extension App\CollectionExtension::map on Collection; > > function foo($x) { > $x > ->map(fn ($value) =3D> $value + 1) > ->map(fn ($value) =3D> $value * 2); > } > This is close to what I was thinking, there might be even more extended map of methods and aliases similar to parentheses block known from traits use. But what is my biggest concern is the amount of changes in opcache cuz this proposal would require storing each Collection class entry patched by a given extension for each class name - but these things are not really runtime at all - meaning we may end up with a blocker because namespaces are not a real thing in PHP. Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000efae4c05e5e6efa3--