Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117889 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81818 invoked from network); 9 Jun 2022 15:00:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2022 15:00:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 24E391804D4 for ; Thu, 9 Jun 2022 09:47:07 -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-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.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 09:47:06 -0700 (PDT) Received: by mail-yb1-f176.google.com with SMTP id p13so42730501ybm.1 for ; Thu, 09 Jun 2022 09:47:06 -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=KZXPxk9Irzhu6xQWVdKV9TSrcYYNyYVokntG+ko0WNo=; b=g9bGZbe0QhAZWEGtlFM2LMorKRik/dV/GLJUIqlK2gjrlgEy26hbxuizV952D2QGVp Bq7NuuK1HWdjtLlk5bEfWCSfePurWe4PLq/BAXCNpcsTLO/L0qih8ENhGO7bv1YWbk+R dxxHNreqwhPpXgqPdshXCsovRXeu9U+AVg+fIpWkFzhcOGRFs7heMRHEOcCn2CqF9Hol 5mNweSrfSPKPxfPxuXaIc2yzr/TkIsmKOWt9t5qR413zmMfjAwdBwoD9mL5fAMF+dWxL Jqb0XGfh7WknikcBEVTEy3xbscF+pUGSwwjuKOYFrQuz6fE/1hpFIN5X8xk92fXqP/8z //QA== 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=KZXPxk9Irzhu6xQWVdKV9TSrcYYNyYVokntG+ko0WNo=; b=U7YHv+Kv1p/uRwUWmVeTv3yEyLoxz6HT5TOKuUKnY+e8wps8Yc9TUFfGbEKAtjeh4J +WAf5lPw/p2yXtABMxxdK1y+o4NL5ZbSHexLRCbKggoM9qHJpFJE7S/QnPYmcvUJIAfp maSpB111GSsxfB70rnRCSQmWT8p6DSfwjl/v/zIGJVdj1LS8YRRv23EmeIqDFG8sc3b4 FGrUxR3yFJkrgd2Fq2iboz9m8g5Z2zk/b1QS6dDX7tjsYUiBeJiOARXxdp0mZ5rnxG+h T8GMvE4w2sHUR32nvaTkC9vHYFpSBBHxI7S4lzFpchBjgjgJyK+fsVxxX1rl7BeH0iOm 6VfA== X-Gm-Message-State: AOAM532rrKFZsN9RXkEJVu7NMTpgGOl5LHJFB5CUZG1sHtS+76QqSh24 FTidUyFw0hRM/jh3CitRE1FZllgaH2v96zIBNgBT6H4BW9JyIg== X-Google-Smtp-Source: ABdhPJwrJ4iGodXmgMYXkf+U7sO0NFXz9HTflpKwoLY55VDUFl+WmizSyjN2nl+h/e6hDSohhXU12hEdxjAQ31f1NKs= X-Received: by 2002:a25:2cd5:0:b0:65d:31f7:c7a5 with SMTP id s204-20020a252cd5000000b0065d31f7c7a5mr40960838ybs.390.1654793225743; Thu, 09 Jun 2022 09:47:05 -0700 (PDT) MIME-Version: 1.0 References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> In-Reply-To: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> Date: Thu, 9 Jun 2022 18:46:53 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000065b1a305e10692c7" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: ocramius@gmail.com (Marco Pivetta) --00000000000065b1a305e10692c7 Content-Type: text/plain; charset="UTF-8" Hey Larry, On Thu, 9 Jun 2022 at 18:34, Larry Garfield wrote: > Last year, Nuno Maduro and I put together an RFC for combining the > multi-line capabilities of long-closures with the auto-capture compactness > of short-closures. That RFC didn't fully go to completion due to concerns > over the performance impact, which Nuno and I didn't have bandwidth to > resolve. > > Arnaud Le Blanc has now picked up the flag with an improved implementation > that includes benchmarks showing an effectively net-zero performance > impact, aka, good news as it avoids over-capturing. > > The RFC has therefore been overhauled accordingly and is now ready for > consideration. > > https://wiki.php.net/rfc/auto-capture-closure > Couple questions: ## nesting these functions within each other What happens when/if we nest these functions? Take this minimal example: ```php $a = 'hello world'; (fn () { (fn () { echo $a; })(); })(); ``` ## capturing `$this` In the past (also present), I had to type `static fn () => ...` or `static function () { ...` all over the place, to avoid implicitly binding `$this` to a closure, causing hidden memory leaks. Assuming following: * these new closures could capture `$this` automatically, once detected * these new closures can optimize away unnecessary variables that aren't captured Would that allow us to get rid of `static fn () {` declarations, when creating one of these closures in an instance method context? Greets, Marco Pivetta https://twitter.com/Ocramius https://ocramius.github.io/ --00000000000065b1a305e10692c7--