Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117896 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 477 invoked from network); 9 Jun 2022 17:53:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2022 17:53:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 06FEA1804F8 for ; Thu, 9 Jun 2022 12:39:33 -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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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, 9 Jun 2022 12:39:32 -0700 (PDT) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-3137eb64b67so50562457b3.12 for ; Thu, 09 Jun 2022 12:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jCMGkJ4XIqP+R4ptuctO/EWKFVMIXLogbGA/k1l+BmA=; b=Z/zIQgwgJPGSW1vmK9m6tMZFzRXMoSLieKWXHah7m2+H7ot0mNzD8JEFYBHKs+xnbL ZwWg/9IzVnysbid4KP3G99L2ct78SNMFOIAzHhp3blGdPxRsnnCZl2sa/BaGKcUjZSOR 75//04D1Sn2jKtnaVvClxBlY1IavZS/HSbudV+sGzRVxPP9PkjavennVxA5reo0IPQsc QWKbd60be1w5Qd7Sa+fJU8CobRKC0Q2IfF/VHq3vlmaEx9KvUEWGDgM4ugTuFPjhyCmA Si6G17pACBjC6bXuzdrdQuMDcS5e3R28x7cxtxJV10DlzoGyH6advLuTKs08F3fszgYo WTNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jCMGkJ4XIqP+R4ptuctO/EWKFVMIXLogbGA/k1l+BmA=; b=avySXInBHKPeqYeMKO32m5x20OVeXEbM2XBHwvQ6BVrBllSsPXv8FAZShu97Veg95F BcaW9K+4GW5pEq8GBk28M3Un2A2MTmdCwsPb0L4oX2jxjA9DY8PJqrJa9HDin5OPsC+P cv+EQl9eyDbsPNI3zwlT56Qehx0GRcp22pWSxaZzV5/eJoQqqkwiKWbFN8H21xYjNqm1 Lk8mCcExlVi7HdblSXmAOAwX9UjYfFg7AQ0pRfn4325GrTujAxwpdrwCbaoRo26daoG7 93JmUnTtYjv4bCFWh57WtwrMA9DtYTtHlTpVLYWyoo+zUhZkJ07GrsHFCgRKd0dNYeMr XfbQ== X-Gm-Message-State: AOAM5303rJuBOG8Cv17MZw4HO0Z+7I2Gkr/AsUE2AuEIovCH10jFzU0+ HEGWP43KlJlosG1R7T8pDrA4wBtLLGy3VHAI8jZdLd+D7DjDkA== X-Google-Smtp-Source: ABdhPJw5YFeeUe3keftP+9e4vMSxF84NuAkXlW5TyBp48+VpiX4iB6AtLETABg9SQ2U5g+TMwCVlBF1cXgcSX2qYrWA= X-Received: by 2002:a81:6ed5:0:b0:313:9109:b86 with SMTP id j204-20020a816ed5000000b0031391090b86mr5211659ywc.509.1654803572095; Thu, 09 Jun 2022 12:39:32 -0700 (PDT) MIME-Version: 1.0 References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <21891029.EfDdHjke4D@arnaud-t490> In-Reply-To: Date: Thu, 9 Jun 2022 21:39:20 +0200 Message-ID: To: Nikita Popov Cc: Arnaud Le Blanc , Larry Garfield , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000167ded05e108fbd5" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: ocramius@gmail.com (Marco Pivetta) --000000000000167ded05e108fbd5 Content-Type: text/plain; charset="UTF-8" Hey Nikita, On Thu, 9 Jun 2022 at 21:35, Nikita Popov wrote: > On Thu, Jun 9, 2022 at 9:29 PM Marco Pivetta wrote: > >> >> On Thu, 9 Jun 2022 at 21:27, Nikita Popov wrote: >> >>> On Thu, Jun 9, 2022 at 8:15 PM Arnaud Le Blanc >>> wrote: >>> >>>> > Would that allow us to get rid of `static fn () {` declarations, when >>>> > creating one of these closures in an instance method context? >>>> >>>> It would be great to get rid of this, but ideally this would apply to >>>> Arrow >>>> Functions and Anonymous Functions as well. This could be a separate RFC. >>>> >>> >>> I've tried this in the past, and this is not possible due to implicit >>> $this uses. See >>> https://wiki.php.net/rfc/arrow_functions_v2#this_binding_and_static_arrow_functions >>> for a brief note on this. The tl;dr is that if your closure does "fn() => >>> Foo::bar()" and Foo happens to be a parent of your current scope and bar() >>> a non-static method, then this performs a scoped instance call that >>> inherits $this. Not binding $this here would result in an Error exception, >>> but the compiler doesn't have any way to know that $this needs to be bound. >>> >>> Regards, >>> Nikita >>> >> >> Hey Nikita, >> >> Do you have another example? Calling instance methods statically is... >> well... deserving a hard crash :| >> > > Maybe easier to understand if you replace Foo::bar() with parent::bar()? > That's the most common spelling for this type of call. > > I agree that the syntax we use for this is unfortunate (because it is > syntactically indistinguishable from a static method call, which it is > *not*), but that's what we have right now, and we can hardly just stop > supporting it. > Dunno, it's a new construct, so perhaps we could do something about it. I'm not suggesting we change the existing `fn` or `function` declarations, but in this case, we're introducing a new construct, and some work already went in to do the eager discovery of by-val variables. Heck, variable variables already wouldn't work here, according to this RFC :D Marco Pivetta https://twitter.com/Ocramius https://ocramius.github.io/ --000000000000167ded05e108fbd5--