Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117897 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1925 invoked from network); 9 Jun 2022 17:56:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2022 17:56:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4E04F180543 for ; Thu, 9 Jun 2022 12:42:36 -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-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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:42:35 -0700 (PDT) Received: by mail-lj1-f171.google.com with SMTP id c30so10736501ljr.9 for ; Thu, 09 Jun 2022 12:42:35 -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=wLaxTqjE6i6O4L8sALox5NRiSryNEP0e/B8+FKs/rek=; b=UFBqJLMWkxOMB1tuqOpZpVeUknRaKDXJ72sjhbR+tm9VXvEO37F73fXJIKfgaJInLE SsQVcl9MC9dlZTQ0WWs1EY4OzoLAcHffTfhbjNSuW12d4m4g4pGCUJzF4eQNbVnm6LNg h7G0OguqR/LsijawdP0SqVnl5R1CX6sb3qFVH2QNDIFcUZMGHxkd6aSNz/1wE9fmQLno HK+BTHHQW2QwJ2iNR2gsGzMffLdnit+83H3sszpQhWwlTre0h+fwwWhysIheUVh9/aqA 5Y58nTsSkswixW4P+fpnsIcVRHsxqu5wGYuqMocpaf5OhtPBHW7+xlZxhZgBWidDBNPy VKNg== 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=wLaxTqjE6i6O4L8sALox5NRiSryNEP0e/B8+FKs/rek=; b=dZdmxEhHapOXk6hbKoY3UdetGq0bTOQ0MK3JZMqXxC5fNUFeAzzGX/obtch1O+8S0+ HQnLXe7wbY5vwSHCD84Ss50Tki9FjmYV8Dqx8dkfRMiPq6sex75UyfGW3RGQweOkFop4 fq51Pyxva/fCN1m/YoRkKYpBnoVhfffug/Os8eoJRSA23434yitPiVUAAV6COmVKhptm 4c7/g7yvzvwSUhhwp/WU8kpwQVp8cCLCd5EJKP9TH/wDnail0g9HqgC2QBjiryXfcZnf 7qLj8QcwMlXwONiuhP4SaXw+6hqs119+W/bZZkdL9c3g4E3mj1EA1e708dxbJ+zVVo+P +rCw== X-Gm-Message-State: AOAM532nXDOd2A4qIPm9FFoJHlojsAaKMfJx5weaZEt4/AlliBAy0YsH vdiPrUlynIJEbs5bxkxuR5EClSQb+lc8hfCu2Eo= X-Google-Smtp-Source: ABdhPJxKzxs0UYjeh5+7TZZ4d0G/eOafLQb5OtCVbYWCO0CLcmmXiNpxXtyuuPiRdyxZfvcyMCXYGlOpk/+bwYYDB2I= X-Received: by 2002:a05:651c:1a13:b0:256:39d4:f630 with SMTP id by19-20020a05651c1a1300b0025639d4f630mr4570864ljb.84.1654803754282; Thu, 09 Jun 2022 12:42:34 -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:42:18 +0200 Message-ID: To: Marco Pivetta Cc: Arnaud Le Blanc , Larry Garfield , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000f2747205e1090526" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000f2747205e1090526 Content-Type: text/plain; charset="UTF-8" On Thu, Jun 9, 2022 at 9:39 PM Marco Pivetta wrote: > 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 > We're not introducing a new construct. We're just extending existing fn() functions to accept {} blocks, with exactly the same semantics as before. I would find it highly concerning if fn() => X and fn() => { return X; } had differences in capture semantics. Those two expressions should be strictly identical -- the former should be desugared to the latter. Nikita --000000000000f2747205e1090526--